| 1 |
<?php |
| 2 |
/** |
| 3 |
* Builder Plugin Compatibility Code |
| 4 |
* |
| 5 |
* @package Themify_Builder |
| 6 |
* @subpackage Themify_Builder/classes |
| 7 |
*/ |
| 8 |
|
| 9 |
class Themify_Builder_Plugin_Compat_facetwp { |
| 10 |
|
| 11 |
static function init() { |
| 12 |
add_action( 'themify_builder_active_enqueue', [ __CLASS__, 'admin_enqueue' ] ); |
| 13 |
add_action( 'themify_builder_module_classes', [ __CLASS__, 'themify_builder_module_classes' ], 1, 4 ); |
| 14 |
} |
| 15 |
|
| 16 |
public static function admin_enqueue() { |
| 17 |
wp_enqueue_script( 'tb-facetwp-admin', THEMIFY_BUILDER_URI .'/includes/plugin-compat/js/facetwp-admin.js', [ 'themify-builder-app-js' ], THEMIFY_VERSION, true ); |
| 18 |
wp_localize_script( 'tb-facetwp-admin', 'tbFacet', [ |
| 19 |
'label' => __( 'FacetWP', 'themify' ), |
| 20 |
'desc' => __( 'Enable integration with FacetWP plugin, the posts display in this module can be filtered.', 'themify' ), |
| 21 |
] ); |
| 22 |
} |
| 23 |
|
| 24 |
public static function themify_builder_module_classes(array $classes,?string $mod_name,?string $element_id,array $options ):array { |
| 25 |
if (!empty( $options['facetwp'] ) ) { |
| 26 |
$classes[] = 'facetwp-template'; |
| 27 |
add_action( 'pre_get_posts', [ __CLASS__, 'pre_get_posts' ] ); |
| 28 |
add_action( 'facetwp_assets', [ __CLASS__, 'facetwp_assets' ] ); |
| 29 |
} |
| 30 |
return $classes; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Enable filtering the wp_query by facet |
| 35 |
*/ |
| 36 |
static function pre_get_posts( $query ) { |
| 37 |
remove_action( 'pre_get_posts', [ __CLASS__, 'pre_get_posts' ] ); |
| 38 |
$query->set( 'facetwp', true ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Load frontend scripts for fixing display of posts |
| 43 |
*/ |
| 44 |
static function facetwp_assets(array $assets ):array { |
| 45 |
$assets['tb-facetwp-front'] = THEMIFY_BUILDER_URI .'/includes/plugin-compat/js/facetwp-front.js'; |
| 46 |
return $assets; |
| 47 |
} |
| 48 |
} |