PluginProbe
Themify Builder / 7.7.0
Themify Builder v7.7.0
7.8.1 7.8.0 7.7.9 7.7.8 7.7.7 7.7.6 7.7.5 7.7.4 7.7.3 7.7.2 trunk 7.6.0 7.6.1 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.8 7.6.9 7.7.0 7.7.1
themify-builder / includes / plugin-compat / facetwp.php

facetwp.php in Themify Builder 7.7.0, at includes/plugin-compat/facetwp.php

48 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }