| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined('WPINC') ) { |
| 4 |
wp_die(); |
| 5 |
} |
| 6 |
|
| 7 |
function flrt_is_woocommerce() |
| 8 |
{ |
| 9 |
if( class_exists('WooCommerce') ){ |
| 10 |
return true; |
| 11 |
} |
| 12 |
return false; |
| 13 |
} |
| 14 |
|
| 15 |
function flrt_get_mobile_width(){ |
| 16 |
return apply_filters( 'wpc_mobile_width', 768 ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* @feature for other popular themes there is possibility to add action to hook get_template_part_{$slug} |
| 21 |
* But it seems we need to detect what current theme is enabled |
| 22 |
*/ |
| 23 |
if( ! function_exists('flrt_wp') ){ |
| 24 |
|
| 25 |
function flrt_wp(){ |
| 26 |
$theme_dependencies = flrt_get_theme_dependencies(); |
| 27 |
|
| 28 |
if( flrt_get_option('show_bottom_widget') === 'on' ) { |
| 29 |
|
| 30 |
if( flrt_get_experimental_option('disable_buttons') !== 'on' ) { |
| 31 |
|
| 32 |
if (flrt_is_woocommerce()) { // It means WooCommerce installed |
| 33 |
|
| 34 |
if( is_woocommerce() ){ // It means is a WooCommerce page |
| 35 |
add_action('woocommerce_before_shop_loop', 'flrt_filters_button', 5); |
| 36 |
add_action('woocommerce_no_products_found', 'flrt_filters_button', 5); |
| 37 |
}else{ |
| 38 |
if (isset($theme_dependencies['button_hook']) && is_array($theme_dependencies['button_hook'])) { |
| 39 |
foreach ($theme_dependencies['button_hook'] as $button_hook) { |
| 40 |
add_action($button_hook, 'flrt_filters_button', 15); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
} else { |
| 46 |
if (isset($theme_dependencies['button_hook']) && is_array($theme_dependencies['button_hook'])) { |
| 47 |
foreach ($theme_dependencies['button_hook'] as $button_hook) { |
| 48 |
add_action($button_hook, 'flrt_filters_button', 15); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
// Add selected terms to the top |
| 57 |
$chips_hooks = flrt_get_option('show_terms_in_content', []); |
| 58 |
|
| 59 |
if( $chips_hooks ){ |
| 60 |
if( is_array( $chips_hooks ) && ! empty( $chips_hooks ) ){ |
| 61 |
foreach ( $chips_hooks as $hook ){ |
| 62 |
add_action( $hook, 'flrt_add_selected_terms_above_the_top' ); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
function wpc_add_selected_terms_above_the_top(){ |
| 70 |
_deprecated_function( __FUNCTION__, '1.0.7', 'flrt_add_selected_terms_above_the_top()' ); |
| 71 |
flrt_add_selected_terms_above_the_top(); |
| 72 |
} |
| 73 |
|
| 74 |
function flrt_add_selected_terms_above_the_top() |
| 75 |
{ |
| 76 |
flrt_show_selected_terms(true); |
| 77 |
} |
| 78 |
|
| 79 |
function flrt_get_theme_dependencies(){ |
| 80 |
$current_theme = strtolower( get_template() ); |
| 81 |
|
| 82 |
$theme_dependencies = array( |
| 83 |
'storefront' => array( |
| 84 |
'posts_container' => '#primary', |
| 85 |
'sidebar_container' => '#secondary', |
| 86 |
'primary_color' => '#96588a', |
| 87 |
'button_hook' => array('storefront_content_top'), |
| 88 |
'chips_hook' => array('storefront_loop_before') |
| 89 |
), |
| 90 |
'hello-elementor' => array( |
| 91 |
'posts_container' => '.page-content', |
| 92 |
'sidebar_container' => '', |
| 93 |
'primary_color' => '#CC3366', |
| 94 |
'button_hook' => '', |
| 95 |
'chips_hook' => '' |
| 96 |
), |
| 97 |
'astra' => array( |
| 98 |
'posts_container' => '#primary', |
| 99 |
'sidebar_container' => '#secondary', |
| 100 |
'primary_color' => '#0274be', |
| 101 |
'button_hook' => '', |
| 102 |
'chips_hook' => '' |
| 103 |
), |
| 104 |
'twentyeleven' => array( |
| 105 |
'posts_container' => '#primary', |
| 106 |
'sidebar_container' => '#secondary', |
| 107 |
'primary_color' => '#1982d1', |
| 108 |
'button_hook' => '', |
| 109 |
'chips_hook' => '' |
| 110 |
), |
| 111 |
'twentytwelve' => array( |
| 112 |
'posts_container' => '#primary', |
| 113 |
'sidebar_container' => '#secondary', |
| 114 |
'primary_color' => '#21759b', |
| 115 |
'button_hook' => '', |
| 116 |
'chips_hook' => '' |
| 117 |
), |
| 118 |
'twentyfourteen' => array( |
| 119 |
'posts_container' => '#primary', |
| 120 |
'sidebar_container' => '#secondary', |
| 121 |
'primary_color' => '#24890d', |
| 122 |
'button_hook' => '', |
| 123 |
'chips_hook' => '' |
| 124 |
), |
| 125 |
'twentyfifteen' => array( |
| 126 |
'posts_container' => '#primary', |
| 127 |
'sidebar_container' => '#secondary', // There are problems on mobile |
| 128 |
// because of sidebar is hidden on mobile until user open header menu. |
| 129 |
'primary_color' => '#333333', |
| 130 |
'button_hook' => '', |
| 131 |
'chips_hook' => '' |
| 132 |
), |
| 133 |
'twentysixteen' => array( |
| 134 |
'posts_container' => '#primary', |
| 135 |
'sidebar_container' => '#secondary', |
| 136 |
'primary_color' => '#007acc', |
| 137 |
'button_hook' => '', |
| 138 |
'chips_hook' => '' |
| 139 |
), |
| 140 |
'twentyseventeen' => array( |
| 141 |
'posts_container' => '#primary', |
| 142 |
'sidebar_container' => '#secondary', |
| 143 |
'primary_color' => '#222222', |
| 144 |
'button_hook' => '', |
| 145 |
'chips_hook' => '' |
| 146 |
), |
| 147 |
'twentynineteen' => array( |
| 148 |
'posts_container' => '#primary', |
| 149 |
'sidebar_container' => '#secondary', |
| 150 |
'primary_color' => '#0073aa', |
| 151 |
'button_hook' => '', |
| 152 |
'chips_hook' => '' |
| 153 |
), |
| 154 |
'twentytwenty' => array( |
| 155 |
'posts_container' => '#site-content', |
| 156 |
'sidebar_container' => '', |
| 157 |
'primary_color' => '#cd2653', |
| 158 |
'button_hook' => '', |
| 159 |
'chips_hook' => '' |
| 160 |
), |
| 161 |
'twentytwentyone' => array( |
| 162 |
'posts_container' => '#content', |
| 163 |
'sidebar_container' => '.widget-area', |
| 164 |
'primary_color' => '#28303d', |
| 165 |
'button_hook' => '', |
| 166 |
'chips_hook' => '' |
| 167 |
), |
| 168 |
'popularfx' => array( |
| 169 |
'posts_container' => '#primary', |
| 170 |
'sidebar_container' => '#secondary', |
| 171 |
'primary_color' => '#0072b7', |
| 172 |
'button_hook' => '', |
| 173 |
'chips_hook' => '' |
| 174 |
), |
| 175 |
'oceanwp' => array( |
| 176 |
'posts_container' => '#primary', |
| 177 |
'sidebar_container' => '#right-sidebar', |
| 178 |
'primary_color' => '#13aff0', |
| 179 |
'button_hook' => array('ocean_before_content'), |
| 180 |
'chips_hook' => array('ocean_before_content') |
| 181 |
), |
| 182 |
'kadence' => array( |
| 183 |
'posts_container' => '#main', |
| 184 |
'sidebar_container' => '#secondary', |
| 185 |
'primary_color' => '#3182ce', |
| 186 |
'button_hook' => array('kadence_before_main_content'), |
| 187 |
'chips_hook' => array('kadence_before_main_content') |
| 188 |
), |
| 189 |
'zakra' => array( |
| 190 |
'posts_container' => '#primary', |
| 191 |
'sidebar_container' => '#secondary', |
| 192 |
'primary_color' => '#269bd1', |
| 193 |
'button_hook' => array('zakra_before_posts_the_loop'), |
| 194 |
'chips_hook' => array('zakra_before_posts_the_loop') |
| 195 |
), |
| 196 |
'neve' => array( |
| 197 |
'posts_container' => '.nv-index-posts', |
| 198 |
'sidebar_container' => '#secondary', // '.nv-sidebar-wrap', |
| 199 |
'primary_color' => '#393939', |
| 200 |
'button_hook' => array('neve_before_loop'), |
| 201 |
'chips_hook' => array('neve_before_loop') |
| 202 |
), |
| 203 |
'hestia' => array( |
| 204 |
'posts_container' => '#woo-products-wrap', |
| 205 |
'sidebar_container' => '#secondary', |
| 206 |
'primary_color' => '#e91e63', |
| 207 |
'button_hook' => array('hestia_before_index_posts_loop'), |
| 208 |
'chips_hook' => array('hestia_before_index_posts_loop') |
| 209 |
), |
| 210 |
'colibri-wp' => array( |
| 211 |
'posts_container' => '.main-row-inner .h-col:not(.colibri-sidebar)', |
| 212 |
'sidebar_container' => '.colibri-sidebar', |
| 213 |
'primary_color' => '#03a9f4', |
| 214 |
'button_hook' => '', |
| 215 |
'chips_hook' => '' |
| 216 |
), |
| 217 |
'teluro' => array( |
| 218 |
'posts_container' => '.main-row-inner .h-col:not(.colibri-sidebar)', |
| 219 |
'sidebar_container' => '.colibri-sidebar', |
| 220 |
'primary_color' => '#f26559', |
| 221 |
'button_hook' => '', |
| 222 |
'chips_hook' => '' |
| 223 |
), |
| 224 |
'numinous' => array( |
| 225 |
'posts_container' => '#primary', |
| 226 |
'sidebar_container' => '#secondary', |
| 227 |
'primary_color' => '#f4ab00', |
| 228 |
'button_hook' => array('numinous_content'), |
| 229 |
'chips_hook' => '' |
| 230 |
), |
| 231 |
'sydney' => array( |
| 232 |
'posts_container' => '#primary', |
| 233 |
'sidebar_container' => '#secondary', |
| 234 |
'primary_color' => '#d65050', |
| 235 |
'button_hook' => array('sydney_before_content'), |
| 236 |
'chips_hook' => '' |
| 237 |
), |
| 238 |
// Commercial themes |
| 239 |
'avada' => array( |
| 240 |
'posts_container' => '#content', |
| 241 |
'sidebar_container' => '#sidebar', |
| 242 |
'primary_color' => '#65bc7b', |
| 243 |
'button_hook' => array('avada_before_main_container'), |
| 244 |
'chips_hook' => '' |
| 245 |
), |
| 246 |
'generatepress' => array( |
| 247 |
'posts_container' => '#primary', |
| 248 |
'sidebar_container' => '.sidebar', |
| 249 |
'primary_color' => '#1e73be', |
| 250 |
'button_hook' => array('generate_before_main_content'), |
| 251 |
'chips_hook' => array('generate_before_main_content') |
| 252 |
), |
| 253 |
'the7' => array( |
| 254 |
'posts_container' => '#content', |
| 255 |
'sidebar_container' => '#sidebar', |
| 256 |
'primary_color' => '', |
| 257 |
'button_hook' => '', |
| 258 |
'chips_hook' => '' |
| 259 |
), |
| 260 |
'dt-the7' => array( |
| 261 |
'posts_container' => '#content', |
| 262 |
'sidebar_container' => '#sidebar', |
| 263 |
'primary_color' => '', |
| 264 |
'button_hook' => '', |
| 265 |
'chips_hook' => '' |
| 266 |
), |
| 267 |
'flatsome' => array( |
| 268 |
'posts_container' => '.shop-container', |
| 269 |
'sidebar_container' => '#shop-sidebar', |
| 270 |
'primary_color' => '#446084', |
| 271 |
'button_hook' => '', |
| 272 |
'chips_hook' => '' |
| 273 |
), |
| 274 |
'betheme' => array( |
| 275 |
'posts_container' => '.sections_group', |
| 276 |
'sidebar_container' => '.sidebar', |
| 277 |
'primary_color' => '', |
| 278 |
'button_hook' => '', |
| 279 |
'chips_hook' => '' |
| 280 |
), |
| 281 |
'bridge' => array( |
| 282 |
'posts_container' => '.container .column1', |
| 283 |
'sidebar_container' => '', |
| 284 |
'primary_color' => '', |
| 285 |
'button_hook' => '', |
| 286 |
'chips_hook' => '' |
| 287 |
), |
| 288 |
'impreza' => array( |
| 289 |
'posts_container' => '#page-content .w-grid-list', |
| 290 |
'sidebar_container' => '', |
| 291 |
'primary_color' => '', |
| 292 |
'button_hook' => '', |
| 293 |
'chips_hook' => '' |
| 294 |
), |
| 295 |
'enfold' => array( |
| 296 |
'posts_container' => 'main.content', |
| 297 |
'sidebar_container' => '', |
| 298 |
'primary_color' => '', |
| 299 |
'button_hook' => '', |
| 300 |
'chips_hook' => '' |
| 301 |
), |
| 302 |
'porto' => array( |
| 303 |
'posts_container' => '#content', |
| 304 |
'sidebar_container' => '', |
| 305 |
'primary_color' => '', |
| 306 |
'button_hook' => '', |
| 307 |
'chips_hook' => '' |
| 308 |
), |
| 309 |
'genesis' => array( |
| 310 |
'posts_container' => '#primary', |
| 311 |
'sidebar_container' => '#secondary', |
| 312 |
'primary_color' => '', |
| 313 |
'button_hook' => '', |
| 314 |
'chips_hook' => '' |
| 315 |
), |
| 316 |
'divi' => array( |
| 317 |
'posts_container' => '#primary', |
| 318 |
'sidebar_container' => '#secondary', |
| 319 |
'primary_color' => '', |
| 320 |
'button_hook' => '', |
| 321 |
'chips_hook' => '' |
| 322 |
), |
| 323 |
'woodmart' => array( |
| 324 |
'posts_container' => '.site-content', |
| 325 |
'sidebar_container' => '#secondary', |
| 326 |
'primary_color' => '#83b735', |
| 327 |
'button_hook' => '', |
| 328 |
'chips_hook' => array( 'woodmart_shop_filters_area', 'woodmart_main_loop') |
| 329 |
) |
| 330 |
); |
| 331 |
|
| 332 |
$theme_dependencies = apply_filters( 'wpc_theme_dependencies', $theme_dependencies ); |
| 333 |
|
| 334 |
if( isset( $theme_dependencies[ $current_theme ] ) ){ |
| 335 |
return $theme_dependencies[ $current_theme ]; |
| 336 |
} |
| 337 |
|
| 338 |
return array( |
| 339 |
'posts_container' => false, |
| 340 |
'sidebar_container' => false, |
| 341 |
'primary_color' => false, |
| 342 |
'button_hook' => array(), |
| 343 |
'chips_hook' => array() |
| 344 |
); |
| 345 |
} |
| 346 |
|
| 347 |
add_action( 'wp', 'flrt_wp' ); |
| 348 |
|
| 349 |
if( ! function_exists('flrt_set_posts_container') ){ |
| 350 |
function flrt_set_posts_container( $theme_posts_container ) |
| 351 |
{ |
| 352 |
$theme_dependencies = flrt_get_theme_dependencies(); |
| 353 |
|
| 354 |
if( isset( $theme_dependencies[ 'posts_container' ] ) ){ |
| 355 |
return $theme_dependencies[ 'posts_container' ]; |
| 356 |
} |
| 357 |
|
| 358 |
return $theme_posts_container; |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
function flrt_set_theme_color($color ){ |
| 363 |
|
| 364 |
$theme_dependencies = flrt_get_theme_dependencies(); |
| 365 |
|
| 366 |
if( $theme_dependencies['primary_color'] ){ |
| 367 |
$color = $theme_dependencies['primary_color']; |
| 368 |
} |
| 369 |
|
| 370 |
return $color; |
| 371 |
} |
| 372 |
|
| 373 |
if( ! function_exists('flrt_init') ){ |
| 374 |
function flrt_init() |
| 375 |
{ |
| 376 |
// Set correct theme posts container |
| 377 |
add_filter('wpc_theme_posts_container', 'flrt_set_posts_container'); |
| 378 |
|
| 379 |
// Set correct theme color |
| 380 |
add_filter('wpc_theme_color', 'flrt_set_theme_color'); |
| 381 |
} |
| 382 |
} |
| 383 |
add_action('init', 'flrt_init'); |
| 384 |
|
| 385 |
/** |
| 386 |
* @todo check the problem with Elementor archive template and different posts queries |
| 387 |
* Different post types, custom and predefined category or custom term |
| 388 |
*/ |
| 389 |
//add_filter( 'elementor/theme/posts_archive/query_posts/query_vars', 'flrt_fix_elementor_query_args' ); |
| 390 |
//add_filter( 'elementor/query/get_query_args/current_query', 'flrt_fix_elementor_query_args' ); |
| 391 |
function flrt_fix_elementor_query_args( $query_args ){ |
| 392 |
$wpManager = \FilterEverything\Filter\Container::instance()->getWpManager(); |
| 393 |
if( ! $wpManager->getQueryVar( 'allowed_filter_page' ) ){ |
| 394 |
return $query_args; |
| 395 |
} |
| 396 |
|
| 397 |
if( isset( $query_args['taxonomy'] ) ){ |
| 398 |
unset( $query_args['taxonomy'] ); |
| 399 |
unset( $query_args['term'] ); |
| 400 |
} |
| 401 |
|
| 402 |
return $query_args; |
| 403 |
} |
| 404 |
|
| 405 |
function flrt_wpml_active(){ |
| 406 |
if( defined('WPML_PLUGIN_BASENAME') ){ |
| 407 |
return true; |
| 408 |
} |
| 409 |
return false; |
| 410 |
} |
| 411 |
|
| 412 |
add_action( 'elementor/editor/before_enqueue_scripts', 'flrt_include_elementor_script' ); |
| 413 |
function flrt_include_elementor_script(){ |
| 414 |
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
| 415 |
$ver = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? rand(0, 1000) : FLRT_PLUGIN_VER; |
| 416 |
wp_enqueue_script('wpc-widgets', FLRT_PLUGIN_URL . 'assets/js/wpc-widgets' . $suffix . '.js', ['jquery', 'jquery-ui-sortable'], $ver, true ); |
| 417 |
wp_enqueue_style('wpc-widgets', FLRT_PLUGIN_URL . 'assets/css/wpc-widgets' . $suffix . '.css', [], $ver ); |
| 418 |
|
| 419 |
$l10n = array( |
| 420 |
'wpcItemNum' => esc_html__( 'Item #', 'filter-everything') |
| 421 |
); |
| 422 |
wp_localize_script( 'wpc-widgets', 'wpcWidgets', $l10n ); |
| 423 |
} |
| 424 |
|
| 425 |
/* |
| 426 |
* Polylang compatibility functions |
| 427 |
* */ |
| 428 |
function flrt_maybe_has_translation( $post_id, $lang = '' ){ |
| 429 |
|
| 430 |
if( function_exists( 'pll_get_post' ) ){ |
| 431 |
$translation_post_id = pll_get_post( $post_id, $lang ); |
| 432 |
if( $translation_post_id ){ |
| 433 |
$post_id = $translation_post_id; |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
return $post_id; |
| 438 |
} |
| 439 |
|
| 440 |
function flrt_pll_pro_active(){ |
| 441 |
if( defined('POLYLANG_PRO') ){ |
| 442 |
return true; |
| 443 |
} |
| 444 |
return false; |
| 445 |
} |
| 446 |
// Allow Filter Sets to be translatable if Polylang PRO activated |
| 447 |
// This make sense for Filter Sets with common locations only |
| 448 |
add_action( 'after_setup_theme', 'flrt_pll_init', 20 ); |
| 449 |
function flrt_pll_init(){ |
| 450 |
if( flrt_pll_pro_active() && defined('FLRT_ALLOW_PLL_TRANSLATIONS') && FLRT_ALLOW_PLL_TRANSLATIONS ){ |
| 451 |
add_filter( 'pll_get_post_types', 'flrt_add_cpt_to_pll', 10, 2 ); |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
function flrt_add_cpt_to_pll( $post_types, $is_settings ) { |
| 456 |
if ( $is_settings ) { |
| 457 |
unset( $post_types[ FLRT_FILTERS_SET_POST_TYPE ] ); |
| 458 |
} else { |
| 459 |
$post_types[ FLRT_FILTERS_SET_POST_TYPE ] = FLRT_FILTERS_SET_POST_TYPE; |
| 460 |
} |
| 461 |
return $post_types; |
| 462 |
} |