gutenberg
1 month ago
option-tabs
2 months ago
display.php
1 month ago
extras.php
8 months ago
widgets.php
3 months ago
display.php
711 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Handles Front-end Display |
| 5 | * |
| 6 | * @copyright Copyright (c) 2015, Jeffrey Carandang |
| 7 | * @since 1.0 |
| 8 | */ |
| 9 | // Exit if accessed directly |
| 10 | if (!defined('ABSPATH')) exit; |
| 11 | |
| 12 | /** |
| 13 | * Handles widget_display_callback filter |
| 14 | * |
| 15 | * @since 1.0 |
| 16 | * @global $widget_options |
| 17 | * @return $instance |
| 18 | */ |
| 19 | |
| 20 | //check if function exists |
| 21 | if (!function_exists('widgetopts_display_callback')) : |
| 22 | function widgetopts_display_callback($instance, $widget, $args) |
| 23 | { |
| 24 | global $widget_options, $current_user, $pagenow, $wp_customize; |
| 25 | |
| 26 | if (empty($instance['extended_widget_opts-' . $widget->id]) && isset($instance['content']) && !empty($instance['content'])) { |
| 27 | $block = parse_blocks($instance['content']); |
| 28 | if (!empty($block[0]) && !empty($block[0]['attrs']) && !empty($block[0]['attrs']['extended_widget_opts'])) { |
| 29 | $instance['extended_widget_opts-' . $widget->id] = $block[0]['attrs']['extended_widget_opts']; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | if (isset($wp_customize)) { |
| 34 | } else if ($pagenow === 'widgets.php' || (defined('REST_REQUEST') && REST_REQUEST)) { |
| 35 | return $instance; |
| 36 | } |
| 37 | |
| 38 | // WPML FIX |
| 39 | $hasWPML = has_filter('wpml_current_language'); |
| 40 | $hasWPML = (function_exists('pll_the_languages')) ? false : $hasWPML; |
| 41 | $default_language = $hasWPML ? apply_filters('wpml_default_language', NULL) : false; |
| 42 | |
| 43 | $hidden = false; |
| 44 | $opts = (isset($instance['extended_widget_opts-' . $widget->id])) ? $instance['extended_widget_opts-' . $widget->id] : array(); |
| 45 | $visibility = array('show' => array(), 'hide' => array()); |
| 46 | |
| 47 | //wordpress pages |
| 48 | $visibility = isset($opts['visibility']) ? $opts['visibility'] : array(); |
| 49 | $visibility_opts = isset($opts['visibility']['options']) ? $opts['visibility']['options'] : 'hide'; |
| 50 | |
| 51 | $is_misc = ('activate' == $widget_options['visibility'] && isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['misc'])) ? true : false; |
| 52 | $is_types = ('activate' == $widget_options['visibility'] && isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['post_type'])) ? true : false; |
| 53 | $is_tax = ('activate' == $widget_options['visibility'] && isset($widget_options['settings']['visibility']) && isset($widget_options['settings']['visibility']['taxonomies'])) ? true : false; |
| 54 | |
| 55 | //check device |
| 56 | if ($widget_options['devices'] == 'activate' && isset($opts['devices']) && !empty($opts['devices'])) { |
| 57 | |
| 58 | //for mobile and tablet |
| 59 | if (wp_is_mobile() || widgetopts_is_mobile() || widgetopts_is_tablet()) { |
| 60 | //mobile |
| 61 | // if (!widgetopts_is_tablet()) { |
| 62 | // if (empty($opts['devices']['options']) || $opts['devices']['options'] == 'hide') { |
| 63 | // if (isset($opts['devices']['mobile']) && $opts['devices']['mobile'] == '1') { |
| 64 | // $hidden = true; |
| 65 | // } |
| 66 | // } else if ($opts['devices']['options'] == 'show') { |
| 67 | // if (!isset($opts['devices']['mobile']) || empty($opts['devices']['mobile'])) { |
| 68 | // $hidden = true; |
| 69 | // } |
| 70 | // } |
| 71 | |
| 72 | // $hidden = apply_filters('widget_options_devices_mobile', $hidden); |
| 73 | // if ($hidden) { |
| 74 | // return false; |
| 75 | // } |
| 76 | // } else { |
| 77 | // //tablet |
| 78 | // if (empty($opts['devices']['options']) || $opts['devices']['options'] == 'hide') { |
| 79 | // if (isset($opts['devices']['tablet']) && $opts['devices']['tablet'] == '1') { |
| 80 | // $hidden = true; |
| 81 | // } |
| 82 | // } else if ($opts['devices']['options'] == 'show') { |
| 83 | // if (!isset($opts['devices']['tablet']) || empty($opts['devices']['tablet'])) { |
| 84 | // $hidden = true; |
| 85 | // } |
| 86 | // } |
| 87 | |
| 88 | // $hidden = apply_filters('widget_options_devices_tablet', $hidden); |
| 89 | // if ($hidden) { |
| 90 | // return false; |
| 91 | // } |
| 92 | // } |
| 93 | |
| 94 | //for a time being filter |
| 95 | if (empty($opts['devices']['options']) || $opts['devices']['options'] == 'hide') { |
| 96 | //if both tablet and mobile are set then hide the widget |
| 97 | if ( |
| 98 | isset($opts['devices']['mobile']) && $opts['devices']['mobile'] == '1' && |
| 99 | isset($opts['devices']['tablet']) && $opts['devices']['tablet'] == '1' |
| 100 | ) { |
| 101 | $hidden = true; |
| 102 | } else { |
| 103 | //else do nothing and css will make the final decision |
| 104 | } |
| 105 | } else if ($opts['devices']['options'] == 'show') { |
| 106 | //if both tablet and mobile are set then hide the widget |
| 107 | if ((!isset($opts['devices']['mobile']) || empty($opts['devices']['mobile'])) && |
| 108 | (!isset($opts['devices']['tablet']) || empty($opts['devices']['tablet'])) |
| 109 | ) { |
| 110 | $hidden = true; |
| 111 | } else { |
| 112 | //else do nothing and css will make the final decision |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | $hidden = apply_filters('widget_options_devices_mobile', $hidden); |
| 117 | if ($hidden) { |
| 118 | return false; |
| 119 | } |
| 120 | } else { |
| 121 | //for desktop |
| 122 | if (empty($opts['devices']['options']) || $opts['devices']['options'] == 'hide') { |
| 123 | if (isset($opts['devices']['desktop']) && $opts['devices']['desktop'] == '1') { |
| 124 | $hidden = true; |
| 125 | } |
| 126 | } else if ($opts['devices']['options'] == 'show') { |
| 127 | if (!isset($opts['devices']['desktop']) || empty($opts['devices']['desktop'])) { |
| 128 | $hidden = true; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | $hidden = apply_filters('widget_options_devices_desktop', $hidden); |
| 133 | if ($hidden) { |
| 134 | return false; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | $isWooPage = false; |
| 140 | if (class_exists('WooCommerce')) { |
| 141 | $wooPageID = 0; |
| 142 | |
| 143 | $wooPageID = (is_shop()) ? get_option('woocommerce_shop_page_id') : $wooPageID; |
| 144 | if ($wooPageID) { |
| 145 | $isWooPage = true; |
| 146 | |
| 147 | $visibility['pages'] = !empty($visibility['pages']) ? $visibility['pages'] : []; |
| 148 | if ($visibility_opts == 'hide' && (array_key_exists($wooPageID, $visibility['pages']) || in_array($wooPageID, $visibility['pages']))) { |
| 149 | $hidden = true; //hide if exists on hidden pages |
| 150 | } elseif ($visibility_opts == 'show' && !array_key_exists($wooPageID, $visibility['pages']) && !in_array($wooPageID, $visibility['pages'])) { |
| 151 | $hidden = true; //hide if doesn't exists on visible pages |
| 152 | } |
| 153 | |
| 154 | //do return to bypass other conditions |
| 155 | $hidden = apply_filters('widget_options_visibility_page', $hidden); |
| 156 | |
| 157 | if ($hidden) { |
| 158 | return false; |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // Normal Pages |
| 164 | if (!$isWooPage) { |
| 165 | if ($is_misc && ((is_home() && is_front_page()) || is_front_page())) { |
| 166 | if (isset($visibility['misc']['home']) && $visibility_opts == 'hide') { |
| 167 | $hidden = true; //hide if checked on hidden pages |
| 168 | } elseif (!isset($visibility['misc']['home']) && $visibility_opts == 'show') { |
| 169 | $hidden = true; //hide if not checked on visible pages |
| 170 | } |
| 171 | |
| 172 | //do return to bypass other conditions |
| 173 | $hidden = apply_filters('widget_options_visibility_home', $hidden); |
| 174 | if ($hidden) { |
| 175 | return false; |
| 176 | } |
| 177 | } elseif ($is_misc && ((!is_front_page() && is_home()))) { //filter for blog page |
| 178 | if (isset($visibility['misc']['blog']) && $visibility_opts == 'hide') { |
| 179 | $hidden = true; //hide if checked on hidden pages |
| 180 | } elseif (!isset($visibility['misc']['blog']) && $visibility_opts == 'show') { |
| 181 | $hidden = true; //hide if not checked on visible pages |
| 182 | } |
| 183 | |
| 184 | //do return to bypass other conditions |
| 185 | $hidden = apply_filters('widget_options_visibility_blog', $hidden); |
| 186 | if ($hidden) { |
| 187 | return false; |
| 188 | } |
| 189 | } elseif ($is_tax && is_category()) { |
| 190 | if (!isset($visibility['categories'])) { |
| 191 | $visibility['categories'] = array(); |
| 192 | } |
| 193 | |
| 194 | if (isset($visibility['tax_terms']['category'])) { |
| 195 | $visibility['categories'] = $visibility['tax_terms']['category']; |
| 196 | } |
| 197 | |
| 198 | $selected_taxterms_page = 1; |
| 199 | if (isset($visibility['tax_terms_page']) && isset($visibility['tax_terms_page']['category'])) { |
| 200 | $selected_taxterms_page = $visibility['tax_terms_page']['category']; |
| 201 | } |
| 202 | |
| 203 | //for taxonomy category checking |
| 204 | if (!isset($visibility['taxonomies'])) { |
| 205 | $visibility['taxonomies'] = array(); |
| 206 | } |
| 207 | //check first the category taxonomy |
| 208 | if ($visibility_opts == 'hide' && array_key_exists('category', $visibility['taxonomies'])) { |
| 209 | $hidden = true; //hide if exists on hidden pages |
| 210 | } elseif ($visibility_opts == 'show' && !array_key_exists('category', $visibility['taxonomies'])) { |
| 211 | $hidden = true; //hide if doesn't exists on visible pages |
| 212 | } |
| 213 | |
| 214 | // WPML TRANSLATION OBJECT FIX |
| 215 | $category_id = ($hasWPML) ? apply_filters('wpml_object_id', get_query_var('cat'), 'category', true, $default_language) : get_query_var('cat'); |
| 216 | |
| 217 | if ($visibility_opts == 'hide' && ((array_key_exists($category_id, $visibility['categories']) && $visibility['categories'][$category_id] == '1') || (in_array($category_id, $visibility['categories']) && ($selected_taxterms_page == 1 || $selected_taxterms_page == 2)) || ($is_misc && isset($visibility['misc']['archives'])))) { |
| 218 | $hidden = true; //hide if exists on hidden pages |
| 219 | } elseif ($visibility_opts == 'show' && ((!array_key_exists($category_id, $visibility['categories']) && empty($visibility['categories'][$category_id])) && !(in_array($category_id, $visibility['categories']) && ($selected_taxterms_page == 1 || $selected_taxterms_page == 2)) && !($is_misc && isset($visibility['misc']['archives'])))) { |
| 220 | $hidden = true; //hide if doesn't exists on visible pages |
| 221 | } elseif (((array_key_exists($category_id, $visibility['categories']) && $visibility['categories'][$category_id] == '1') || (in_array($category_id, $visibility['categories']) && ($selected_taxterms_page == 1 || $selected_taxterms_page == 2))) && $visibility_opts == 'hide') { |
| 222 | $hidden = true; //hide to all categories |
| 223 | } elseif (((array_key_exists($category_id, $visibility['categories']) && $visibility['categories'][$category_id] == '1') || (in_array($category_id, $visibility['categories']) && ($selected_taxterms_page == 1 || $selected_taxterms_page == 2)) || ($is_misc && isset($visibility['misc']['archives']))) && $visibility_opts == 'show') { |
| 224 | $hidden = false; //hide to all categories |
| 225 | } |
| 226 | |
| 227 | if ($visibility_opts == 'show' && array_key_exists('category', $visibility['taxonomies'])) { |
| 228 | $hidden = false; //hide if doesn't exists on visible pages |
| 229 | } |
| 230 | |
| 231 | //do return to bypass other conditions |
| 232 | $hidden = apply_filters('widget_options_visibility_categories', $hidden); |
| 233 | if ($hidden) { |
| 234 | return false; |
| 235 | } |
| 236 | } elseif ($is_tax && is_tag()) { |
| 237 | if (!isset($visibility['tags'])) { |
| 238 | $visibility['tags'] = array(); |
| 239 | } |
| 240 | |
| 241 | if (((isset($visibility['taxonomies']['post_tag']) || ($is_misc && isset($visibility['misc']['archives']))) && $visibility_opts == 'hide') || |
| 242 | ((!isset($visibility['taxonomies']['post_tag']) && !($is_misc && isset($visibility['misc']['archives']))) && $visibility_opts == 'show') |
| 243 | ) { |
| 244 | $hidden = true; //hide to all tags |
| 245 | } elseif (isset($visibility['taxonomies']['post_tag']) && $visibility_opts == 'show') { |
| 246 | $hidden = false; //hide to all tags |
| 247 | } |
| 248 | |
| 249 | //do return to bypass other conditions |
| 250 | $hidden = apply_filters('widget_options_visibility_tags', $hidden); |
| 251 | if ($hidden) { |
| 252 | return false; |
| 253 | } |
| 254 | } elseif ($is_tax && is_tax()) { |
| 255 | $term = get_queried_object(); |
| 256 | if (!isset($visibility['taxonomies'])) { |
| 257 | $visibility['taxonomies'] = array(); |
| 258 | } |
| 259 | |
| 260 | if ($visibility_opts == 'hide' && (!is_null($term) && isset($term->taxonomy) && (array_key_exists($term->taxonomy, $visibility['taxonomies'])) || ($is_misc && is_archive() && isset($visibility['misc']['archives'])))) { |
| 261 | $hidden = true; //hide if exists on hidden pages |
| 262 | } elseif ($visibility_opts == 'show' && !(!is_null($term) && isset($term->taxonomy) && array_key_exists($term->taxonomy, $visibility['taxonomies'])) && !($is_misc && is_archive() && isset($visibility['misc']['archives']))) { |
| 263 | $hidden = true; //hide if doesn't exists on visible pages |
| 264 | } |
| 265 | |
| 266 | //do return to bypass other conditions |
| 267 | $hidden = apply_filters('widget_options_visibility_taxonomies', $hidden); |
| 268 | if ($hidden) { |
| 269 | return false; |
| 270 | } |
| 271 | } elseif ($is_misc && is_archive()) { |
| 272 | if (isset($visibility['misc']['archives']) && $visibility_opts == 'hide') { |
| 273 | $hidden = true; //hide if checked on hidden pages |
| 274 | } elseif (!isset($visibility['misc']['archives']) && $visibility_opts == 'show') { |
| 275 | $hidden = true; //hide if not checked on visible pages |
| 276 | } |
| 277 | |
| 278 | //do return to bypass other conditions |
| 279 | $hidden = apply_filters('widget_options_visibility_archives', $hidden); |
| 280 | if ($hidden) { |
| 281 | return false; |
| 282 | } |
| 283 | } elseif ($is_misc && is_404()) { |
| 284 | if (isset($visibility['misc']['404']) && $visibility_opts == 'hide') { |
| 285 | $hidden = true; //hide if checked on hidden pages |
| 286 | } elseif (!isset($visibility['misc']['404']) && $visibility_opts == 'show') { |
| 287 | $hidden = true; //hide if not checked on visible pages |
| 288 | } |
| 289 | |
| 290 | //do return to bypass other conditions |
| 291 | $hidden = apply_filters('widget_options_visibility_404', $hidden); |
| 292 | if ($hidden) { |
| 293 | return false; |
| 294 | } |
| 295 | } elseif ($is_misc && is_search()) { |
| 296 | if (isset($visibility['misc']['search']) && $visibility_opts == 'hide') { |
| 297 | $hidden = true; //hide if checked on hidden pages |
| 298 | } elseif (!isset($visibility['misc']['search']) && $visibility_opts == 'show') { |
| 299 | $hidden = true; //hide if not checked on visible pages |
| 300 | } |
| 301 | |
| 302 | //do return to bypass other conditions |
| 303 | $hidden = apply_filters('widget_options_visibility_search', $hidden); |
| 304 | if ($hidden) { |
| 305 | return false; |
| 306 | } |
| 307 | } elseif (is_single() && !is_page()) { |
| 308 | global $post; |
| 309 | $type = ''; |
| 310 | if (!$post) { |
| 311 | $current_post = get_post(); |
| 312 | $type = $current_post->post_type; |
| 313 | } else { |
| 314 | $type = $post->post_type; |
| 315 | } |
| 316 | |
| 317 | if ($is_misc) { |
| 318 | if (isset($visibility['misc']['single']) && $visibility_opts == 'show') { |
| 319 | return $instance; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | if (isset($visibility['tax_terms']['category'])) { |
| 324 | $visibility['categories'] = $visibility['tax_terms']['category']; |
| 325 | } |
| 326 | |
| 327 | $selected_taxterms_page = 1; |
| 328 | if (isset($visibility['tax_terms_page']) && isset($visibility['tax_terms_page']['category'])) { |
| 329 | $selected_taxterms_page = $visibility['tax_terms_page']['category']; |
| 330 | } |
| 331 | |
| 332 | if (!isset($visibility['types'])) { |
| 333 | $visibility['types'] = array(); |
| 334 | } |
| 335 | if ($visibility_opts == 'hide' && (array_key_exists($type, $visibility['types']) || ($is_misc && isset($visibility['misc']['single'])))) { |
| 336 | $hidden = true; //hide if exists on hidden pages |
| 337 | } elseif ($visibility_opts == 'show' && (!array_key_exists($type, $visibility['types']) && (($is_misc && (!isset($visibility['misc']['single']))) || !$is_misc))) { |
| 338 | $hidden = true; //hide if doesn't exists on visible pages |
| 339 | } |
| 340 | |
| 341 | // do return to bypass other conditions |
| 342 | $hidden = apply_filters('widget_options_visibility_types', $hidden); |
| 343 | //hide posts assign on category |
| 344 | if (!isset($visibility['categories'])) { |
| 345 | $visibility['categories'] = array(); |
| 346 | } |
| 347 | if (isset($visibility['categories']['all_categories']) && $visibility_opts == 'hide') { |
| 348 | $hidden = true; //hide to all categories |
| 349 | } elseif (isset($visibility['categories']['all_categories']) && $visibility_opts == 'show') { |
| 350 | $hidden = false; //hide to all categories |
| 351 | } elseif (!isset($visibility['categories']['all_categories']) && !empty($visibility['categories'])) { |
| 352 | $cats = wp_get_post_categories(get_the_ID()); |
| 353 | if (is_array($cats) && !empty($cats)) { |
| 354 | $checked_cats = array_keys($visibility['categories']); |
| 355 | $checked_cats = (intval($checked_cats[0]) == 0) ? $visibility['categories'] : $checked_cats; |
| 356 | $intersect = array_intersect($cats, $checked_cats); |
| 357 | if (!empty($intersect) && $visibility_opts == 'hide') { |
| 358 | if ($selected_taxterms_page == 1 || $selected_taxterms_page == 3) { |
| 359 | $hidden = true; |
| 360 | } |
| 361 | } elseif (!empty($intersect) && $visibility_opts == 'show') { |
| 362 | if ($selected_taxterms_page == 1 || $selected_taxterms_page == 3) { |
| 363 | $hidden = false; |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | // do return to bypass other conditions |
| 369 | $hidden = apply_filters('widget_options_visibility_post_category', $hidden); |
| 370 | if ($hidden) { |
| 371 | return false; |
| 372 | } |
| 373 | // echo $type; |
| 374 | } elseif ($is_types && (is_page() || get_post_type(get_the_ID()) == 'page')) { |
| 375 | global $post; |
| 376 | |
| 377 | // WPML FIX |
| 378 | $page_id = get_queried_object_id(); |
| 379 | $parent_id = wp_get_post_parent_id($page_id); |
| 380 | |
| 381 | $pageID = ($hasWPML) ? apply_filters('wpml_object_id', $page_id, 'page', true, $default_language) : $page_id; |
| 382 | $parentID = ($hasWPML) ? apply_filters('wpml_object_id', $parent_id, 'page', true, $default_language) : $parent_id; |
| 383 | |
| 384 | //do post type condition first |
| 385 | if (isset($visibility['types']) && isset($visibility['types']['page'])) { |
| 386 | if ($visibility_opts == 'hide' && array_key_exists('page', $visibility['types'])) { |
| 387 | $hidden = true; //hide if exists on hidden pages |
| 388 | } elseif ($visibility_opts == 'show' && !array_key_exists('page', $visibility['types'])) { |
| 389 | $hidden = true; //hide if doesn't exists on visible pages |
| 390 | } |
| 391 | } else { |
| 392 | //do per pages condition |
| 393 | if (!isset($visibility['pages'])) { |
| 394 | $visibility['pages'] = array(); |
| 395 | } |
| 396 | |
| 397 | $page_in_array = in_array($pageID, $visibility['pages']); |
| 398 | //for the compatibility of the data of lower version 3.8.10 and below |
| 399 | if (array_key_exists($pageID, $visibility['pages'])) { |
| 400 | if ($visibility['pages'][$pageID] == 1) { |
| 401 | $page_in_array = true; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | if ($visibility_opts == 'hide' && $page_in_array) { |
| 406 | $hidden = true; //hide if exists on hidden pages |
| 407 | } elseif ($visibility_opts == 'show' && $pageID == 0) { |
| 408 | //for old versin v3.8.10 and below, need to resave the widget option |
| 409 | if (!in_array($pageID, $visibility['pages'])) { |
| 410 | $hidden = true; |
| 411 | } |
| 412 | } elseif ($visibility_opts == 'show' && !$page_in_array) { |
| 413 | $hidden = true; //hide if doesn't exists on visible pages |
| 414 | } |
| 415 | } |
| 416 | //do return to bypass other conditions |
| 417 | $hidden = apply_filters('widget_options_visibility_page', $hidden); |
| 418 | if ($hidden) { |
| 419 | return false; |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | //end wordpress pages |
| 424 | |
| 425 | |
| 426 | //ACF |
| 427 | if (isset($widget_options['acf']) && 'activate' == $widget_options['acf']) { |
| 428 | if (isset($visibility['acf']['field']) && !empty($visibility['acf']['field'])) { |
| 429 | $acf = get_field_object($visibility['acf']['field']); |
| 430 | |
| 431 | if ($acf && is_array($acf)) { |
| 432 | $acf_visibility = (isset($visibility['acf']) && isset($visibility['acf']['visibility'])) ? $visibility['acf']['visibility'] : 'hide'; |
| 433 | |
| 434 | //handle repeater fields |
| 435 | if (isset($acf['value'])) { |
| 436 | if (is_array($acf['value'])) { |
| 437 | $acf['value'] = implode(', ', array_map(function ($acf_array_value) { |
| 438 | $acf_implode = ''; |
| 439 | if (is_array($acf_array_value)) { |
| 440 | $acf_implode = implode(',', array_filter($acf_array_value)); |
| 441 | } else { |
| 442 | $acf_implode = $acf_array_value; |
| 443 | } |
| 444 | return $acf_implode; |
| 445 | }, $acf['value'])); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | switch ($visibility['acf']['condition']) { |
| 450 | case 'equal': |
| 451 | if (isset($acf['value'])) { |
| 452 | if ('show' == $acf_visibility && $acf['value'] == $visibility['acf']['value']) { |
| 453 | $hidden = false; |
| 454 | } else if ('show' == $acf_visibility && $acf['value'] != $visibility['acf']['value']) { |
| 455 | $hidden = true; |
| 456 | } else if ('hide' == $acf_visibility && $acf['value'] == $visibility['acf']['value']) { |
| 457 | $hidden = true; |
| 458 | } else if ('hide' == $acf_visibility && $acf['value'] != $visibility['acf']['value']) { |
| 459 | $hidden = false; |
| 460 | } |
| 461 | } |
| 462 | break; |
| 463 | |
| 464 | case 'not_equal': |
| 465 | if (isset($acf['value'])) { |
| 466 | if ('show' == $acf_visibility && $acf['value'] == $visibility['acf']['value']) { |
| 467 | $hidden = true; |
| 468 | } else if ('show' == $acf_visibility && $acf['value'] != $visibility['acf']['value']) { |
| 469 | $hidden = false; |
| 470 | } else if ('hide' == $acf_visibility && $acf['value'] == $visibility['acf']['value']) { |
| 471 | $hidden = false; |
| 472 | } else if ('hide' == $acf_visibility && $acf['value'] != $visibility['acf']['value']) { |
| 473 | $hidden = true; |
| 474 | } |
| 475 | } |
| 476 | break; |
| 477 | |
| 478 | case 'contains': |
| 479 | if (isset($acf['value'])) { |
| 480 | if ('show' == $acf_visibility && strpos($acf['value'], $visibility['acf']['value']) !== false) { |
| 481 | $hidden = false; |
| 482 | } else if ('show' == $acf_visibility && strpos($acf['value'], $visibility['acf']['value']) === false) { |
| 483 | $hidden = true; |
| 484 | } else if ('hide' == $acf_visibility && strpos($acf['value'], $visibility['acf']['value']) !== false) { |
| 485 | $hidden = true; |
| 486 | } else if ('hide' == $acf_visibility && strpos($acf['value'], $visibility['acf']['value']) === false) { |
| 487 | $hidden = false; |
| 488 | } |
| 489 | } |
| 490 | break; |
| 491 | |
| 492 | case 'not_contains': |
| 493 | if (isset($acf['value'])) { |
| 494 | if ('show' == $acf_visibility && strpos($acf['value'], $visibility['acf']['value']) !== false) { |
| 495 | $hidden = true; |
| 496 | } else if ('show' == $acf_visibility && strpos($acf['value'], $visibility['acf']['value']) === false) { |
| 497 | $hidden = false; |
| 498 | } else if ('hide' == $acf_visibility && strpos($acf['value'], $visibility['acf']['value']) !== false) { |
| 499 | $hidden = false; |
| 500 | } else if ('hide' == $acf_visibility && strpos($acf['value'], $visibility['acf']['value']) === false) { |
| 501 | $hidden = true; |
| 502 | } |
| 503 | } |
| 504 | break; |
| 505 | |
| 506 | case 'empty': |
| 507 | if ('show' == $acf_visibility && empty($acf['value'])) { |
| 508 | $hidden = false; |
| 509 | } else if ('show' == $acf_visibility && !empty($acf['value'])) { |
| 510 | $hidden = true; |
| 511 | } elseif ('hide' == $acf_visibility && empty($acf['value'])) { |
| 512 | $hidden = true; |
| 513 | } else if ('hide' == $acf_visibility && !empty($acf['value'])) { |
| 514 | $hidden = false; |
| 515 | } |
| 516 | break; |
| 517 | |
| 518 | case 'not_empty': |
| 519 | if ('show' == $acf_visibility && empty($acf['value'])) { |
| 520 | $hidden = true; |
| 521 | } else if ('show' == $acf_visibility && !empty($acf['value'])) { |
| 522 | $hidden = false; |
| 523 | } elseif ('hide' == $acf_visibility && empty($acf['value'])) { |
| 524 | $hidden = false; |
| 525 | } else if ('hide' == $acf_visibility && !empty($acf['value'])) { |
| 526 | $hidden = true; |
| 527 | } |
| 528 | break; |
| 529 | |
| 530 | default: |
| 531 | # code... |
| 532 | break; |
| 533 | } |
| 534 | |
| 535 | // //do return to bypass other conditions |
| 536 | $hidden = apply_filters('widget_options_visibility_acf', $hidden); |
| 537 | if ($hidden) { |
| 538 | return false; |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | //login state |
| 545 | if (isset($widget_options['state']) && 'activate' == $widget_options['state'] && isset($opts['roles'])) { |
| 546 | if (isset($opts['roles']['state']) && !empty($opts['roles']['state'])) { |
| 547 | //do state action here |
| 548 | if ($opts['roles']['state'] == 'out' && is_user_logged_in()) { |
| 549 | return false; |
| 550 | } else if ($opts['roles']['state'] == 'in' && !is_user_logged_in()) { |
| 551 | return false; |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | if ('activate' == $widget_options['logic']) { |
| 557 | // Display widget logic - New snippet-based system |
| 558 | if (isset($opts['class']['logic_snippet_id']) && !empty($opts['class']['logic_snippet_id'])) { |
| 559 | $snippet_id = $opts['class']['logic_snippet_id']; |
| 560 | |
| 561 | // Use the API to process snippet logic |
| 562 | if (class_exists('WidgetOpts_Snippets_API')) { |
| 563 | $result = WidgetOpts_Snippets_API::execute_snippet($snippet_id); |
| 564 | if ($result === false) { |
| 565 | return false; |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | // Legacy support for old inline logic (backup during migration) |
| 570 | elseif (isset($opts['class']['logic']) && !empty($opts['class']['logic'])) { |
| 571 | // Flag that legacy migration is needed |
| 572 | if (!get_option('wopts_display_logic_migration_required', false)) { |
| 573 | update_option('wopts_display_logic_migration_required', true); |
| 574 | } |
| 575 | |
| 576 | $display_logic = stripslashes(trim($opts['class']['logic'])); |
| 577 | $display_logic = apply_filters('widget_options_logic_override', $display_logic); |
| 578 | $display_logic = apply_filters('extended_widget_options_logic_override', $display_logic); |
| 579 | if ($display_logic === false) { |
| 580 | return false; |
| 581 | } |
| 582 | if ($display_logic === true) { |
| 583 | return true; |
| 584 | } |
| 585 | $display_logic = htmlspecialchars_decode($display_logic, ENT_QUOTES); |
| 586 | if (!widgetopts_safe_eval_trusted($display_logic)) { |
| 587 | return false; |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | if ('activate' == $widget_options['hide_title']) { |
| 593 | //hide widget title |
| 594 | if (isset($instance['title']) && isset($opts['class']) && isset($opts['class']['title']) && '1' == $opts['class']['title']) { |
| 595 | $instance['title'] = ''; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | return $instance; |
| 600 | } |
| 601 | add_filter('widget_display_callback', 'widgetopts_display_callback', 50, 3); |
| 602 | endif; |
| 603 | |
| 604 | //Don't show widget title |
| 605 | if (!function_exists('widgetopts_remove_title')) : |
| 606 | function widgetopts_remove_title($widget_title, $instance = array(), $widget_id = '') |
| 607 | { |
| 608 | global $widget_options; |
| 609 | if ('activate' == $widget_options['hide_title'] && is_array($instance) && !empty($instance)) { |
| 610 | foreach ($instance as $key => $value) { |
| 611 | if (substr($key, 0, 20) == 'extended_widget_opts') { |
| 612 | $opts = (isset($instance[$key])) ? (array)$instance[$key] : array(); |
| 613 | |
| 614 | if (isset($opts['class']) && isset($opts['class']['title']) && '1' == $opts['class']['title']) { |
| 615 | return; |
| 616 | } |
| 617 | |
| 618 | break; |
| 619 | } |
| 620 | } |
| 621 | return $widget_title; |
| 622 | } else { |
| 623 | return ($widget_title); |
| 624 | } |
| 625 | } |
| 626 | add_filter('widget_title', 'widgetopts_remove_title', 10, 4); |
| 627 | endif; |
| 628 | |
| 629 | /* |
| 630 | * Add custom classes on dynamic_sidebar_params filter |
| 631 | */ |
| 632 | if (!function_exists('widgetopts_add_classes')) : |
| 633 | function widgetopts_add_classes($params) |
| 634 | { |
| 635 | global $widget_options, $wp_registered_widget_controls; |
| 636 | $classe_to_add = ''; |
| 637 | $id_base = $wp_registered_widget_controls[$params[0]['widget_id']]['id_base']; |
| 638 | $instance = get_option('widget_' . $id_base); |
| 639 | |
| 640 | $num = substr($params[0]['widget_id'], -1); |
| 641 | if (isset($wp_registered_widget_controls[$params[0]['widget_id']]['params'][0]['number'])) { |
| 642 | $num = $wp_registered_widget_controls[$params[0]['widget_id']]['params'][0]['number']; |
| 643 | } elseif (isset($wp_registered_widget_controls[$params[0]['widget_id']]['callback']) && is_array($wp_registered_widget_controls[$params[0]['widget_id']]['callback'])) { |
| 644 | if (isset($wp_registered_widget_controls[$params[0]['widget_id']]['callback'][0]) && isset($wp_registered_widget_controls[$params[0]['widget_id']]['callback'][0]->number)) { |
| 645 | $num = $wp_registered_widget_controls[$params[0]['widget_id']]['callback'][0]->number; |
| 646 | } |
| 647 | } |
| 648 | if (isset($instance[$num])) { |
| 649 | $opts = (isset($instance[$num]['extended_widget_opts-' . $params[0]['widget_id']])) ? $instance[$num]['extended_widget_opts-' . $params[0]['widget_id']] : array(); |
| 650 | if (empty($opts) && isset($instance[$num]['content']) && !empty($instance[$num]['content'])) { |
| 651 | /* if $opts is empty, try to get data from blocks */ |
| 652 | $block = parse_blocks($instance[$num]['content']); |
| 653 | if (!empty($block[0]) && !empty($block[0]['attrs'])) { |
| 654 | if (!empty($block[0]['attrs']['extended_widget_opts'])) { |
| 655 | $opts = $block[0]['attrs']['extended_widget_opts']; |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | } else { |
| 660 | $opts = array(); |
| 661 | } |
| 662 | |
| 663 | $custom_class = isset($opts['class']) ? $opts['class'] : ''; |
| 664 | $widget_id_set = $params[0]['widget_id']; |
| 665 | |
| 666 | if ('activate' == $widget_options['classes'] && isset($widget_options['settings']['classes'])) { |
| 667 | //don't add the IDs when the setting is set to NO |
| 668 | if (isset($widget_options['settings']['classes']['id'])) { |
| 669 | if (is_array($custom_class) && isset($custom_class['id']) && !empty($custom_class['id'])) { |
| 670 | $custom_class['id'] = sanitize_html_class($custom_class['id']); |
| 671 | $params[0]['before_widget'] = preg_replace('/id="[^"]*/', "id=\"{$custom_class['id']}", $params[0]['before_widget'], 1); |
| 672 | $widget_id_set = $custom_class['id']; |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | $get_classes = widgetopts_classes_generator($opts, $widget_options, $widget_options['settings']); |
| 678 | |
| 679 | //double check array |
| 680 | if (!is_array($get_classes)) { |
| 681 | $get_classes = array(); |
| 682 | } |
| 683 | |
| 684 | if ('activate' == $widget_options['classes']) { |
| 685 | if (isset($widget_options['settings']['classes']['auto'])) { |
| 686 | //do nothing |
| 687 | } else { |
| 688 | //check if widget class exists |
| 689 | if ((strpos($params[0]['before_widget'], '"widget ') !== false) || |
| 690 | (strpos($params[0]['before_widget'], ' widget ') !== false) || |
| 691 | (strpos($params[0]['before_widget'], ' widget"') !== false) |
| 692 | ) { |
| 693 | //do nothing |
| 694 | } else { |
| 695 | $get_classes[] = 'widget'; |
| 696 | } |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | if (!empty($get_classes)) { |
| 701 | $classes = 'class="' . (implode(' ', $get_classes)) . ' '; |
| 702 | $params[0]['before_widget'] = str_replace('class="', $classes, $params[0]['before_widget']); |
| 703 | } |
| 704 | |
| 705 | // $params[0]['before_widget'] = str_replace('class="', ' data-animation="asdf" class="', $params[0]['before_widget']); |
| 706 | |
| 707 | return $params; |
| 708 | } |
| 709 | add_filter('dynamic_sidebar_params', 'widgetopts_add_classes'); |
| 710 | endif; |
| 711 |