| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Compatibility\Wpml; |
| 5 |
|
| 6 |
// If this file is called directly, abort. |
| 7 |
if ( ! defined( 'WPINC' ) ) { |
| 8 |
die(); |
| 9 |
} |
| 10 |
|
| 11 |
use JFB_Modules\Option_Field\Interfaces\Support_Option_Query_It; |
| 12 |
use Jet_Form_Builder\Blocks\Types\Base; |
| 13 |
use JFB_Components\Module\Base_Module_It; |
| 14 |
|
| 15 |
class Wpml implements Base_Module_It { |
| 16 |
|
| 17 |
public function rep_item_id() { |
| 18 |
return 'wpml'; |
| 19 |
} |
| 20 |
|
| 21 |
public function condition(): bool { |
| 22 |
return defined( 'ICL_SITEPRESS_VERSION' ); |
| 23 |
} |
| 24 |
|
| 25 |
public function init_hooks() { |
| 26 |
if ( ! jet_form_builder()->has_module( 'option-query' ) ) { |
| 27 |
add_filter( |
| 28 |
'jet-form-builder/render-choice/query-options/posts', |
| 29 |
array( $this, 'remove_suppress_filters' ) |
| 30 |
); |
| 31 |
|
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
add_action( |
| 36 |
'jet-form-builder/option-query/set-in-block', |
| 37 |
array( $this, 'on_set_in_block' ) |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
public function remove_hooks() { |
| 42 |
if ( ! jet_form_builder()->has_module( 'option-query' ) ) { |
| 43 |
remove_filter( |
| 44 |
'jet-form-builder/render-choice/query-options/posts', |
| 45 |
array( $this, 'remove_suppress_filters' ) |
| 46 |
); |
| 47 |
|
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
remove_action( |
| 52 |
'jet-form-builder/option-query/set-in-block', |
| 53 |
array( $this, 'on_set_in_block' ) |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
public function remove_suppress_filters( array $args ): array { |
| 58 |
$args['suppress_filters'] = false; |
| 59 |
|
| 60 |
return $args; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* @param Base|Support_Option_Query_It $block |
| 65 |
*/ |
| 66 |
public function on_set_in_block( Base $block ) { |
| 67 |
switch ( $block->get_query()->rep_item_id() ) { |
| 68 |
case 'posts': |
| 69 |
$block->get_query()->set_query( 'suppress_filters', false ); |
| 70 |
break; |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
|