Gists

1 year ago
<?php

/** Temporary fix for indexer bug in FacetWP 4.2.3 **/
/** Add to your (child) theme's functions.php **/
/** Remove again when FacetWP is updated to 4.2.4 **/

add_filter( 'facetwp_indexer_query_args', function( $args ) {
    $args['post_type'] = array_merge( $args['post_type'], get_post_types( [
        'exclude_from_search' => false,
        '_builtin' => true
    ]) );
    return $args;
});
4 years ago
<?php

/** fix for second lang being deleted on post index */
add_filter( 'facetwp_indexer_query_args', function( $args ) {
    if ( function_exists( 'is_checkout' ) && is_checkout() ) {
        return $args;
    }
        
    do_action( 'wpml_switch_language', 'all' );

    $args['suppress_filters'] = true; // query posts in all languages
    return $args;
}, 11 );
5 years ago
<?php

// Add to your (child) theme's functions.php

add_filter( 'facetwp_indexer_query_args', function( $args ) {
    if ( in_array( 'product', (array) $args['post_type'] ) ) {
        $args['post_status'] = [ 'publish', 'private' ];
    }
    return $args;
}, 20 );
6 years ago
<?php

add_filter( 'facetwp_indexer_query_args', function( $args ) {
    $args['post_type'] = (array) get_post_types();
    $args['post_type'][] = 'wprm_recipe';
    return $args;
});
6 years ago
<?php
/** inherit adds attachment indexing **/
add_filter( 'facetwp_indexer_query_args', function( $args ) {
    $args['post_status'] = array( 'publish', 'inherit' );
    return $args;
});

/** post_mime_type is the column in the posts table to add **/
add_filter( 'facetwp_facet_sources', function( $sources ) {
    $sources['posts']['choices']['post_mime_type'] = 'Media Type';
    return $sources;
});

/** modifies string for mine type
 ** example image/png becomes image
 **/
add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'post_mime_type' == $params['facet_source'] ) {
		  $value = $params['facet_display_value'];
		  $value = substr( $value, 0, strpos( $value, '/' ) );
		  $params['facet_value'] = $params['facet_display_value'] = $value;
    }
    return $params;
}, 10, 2 );
6 years ago
<?php
/*
Plugin Name: FacetWP - Polylang
Description: Polylang support for FacetWP
Version: 1.2.2
Author: FacetWP, LLC
Author URI: https://facetwp.com/
GitHub URI: facetwp/facetwp-polylang
*/

defined( 'ABSPATH' ) or exit;

class FWP_Polylang
{

    function __construct() {
        add_action( 'init' , array( $this, 'init' ) );
    }


    /**
     * Intialize
     */
    function init() {

        if ( function_exists( 'FWP' ) && function_exists( 'pll_register_string' ) ) {
            add_action( 'wp_footer', array( $this, 'wp_footer' ), 30 );
            add_action( 'admin_init', array( $this, 'register_strings' ) );
            add_action( 'facetwp_refresh', array( $this, 'set_langcode' ) );

            add_filter( 'facetwp_query_args', array( $this, 'facetwp_query_args' ), 10, 2 );
            add_filter( 'facetwp_indexer_query_args', array( $this, 'facetwp_indexer_query_args' ) );
            add_filter( 'facetwp_render_params', array( $this, 'support_preloader' ) );
            add_filter( 'facetwp_i18n', array( $this, 'facetwp_i18n' ) );
        }
        else {
            add_action( 'admin_notices', array( $this, 'admin_notice' ) );
        }
    }


    /**
     * Put the language into FWP_HTTP
     */
    function wp_footer() {
        if ( function_exists( 'pll_current_language' ) ) {
            $lang = pll_current_language();
            echo "<script>if ('undefined' != typeof FWP_HTTP) FWP_HTTP.lang = '$lang';</script>";
        }
    }


    /**
     * On ajax refreshes, set the langcode
     */
    function set_langcode() {
        if ( isset( FWP()->facet->http_params['lang'] ) ) {
            $_GET['lang'] = FWP()->facet->http_params['lang'];
        }
    }


    /**
     * Support FacetWP preloading (3.0.4+)
     */
    function support_preloader( $params ) {
        if ( isset( $params['is_preload'] ) && function_exists( 'pll_current_language' ) ) {
            $params['http_params']['lang'] = pll_current_language();
        }

        return $params;
    }


    /**
     * Query posts for the current language
     */
    function facetwp_query_args( $args, $class ) {
        if ( isset( $class->http_params['lang'] ) ) {
            $args['lang'] = $class->http_params['lang'];
        }

        return $args;
    }


    /**
     * Index all languages
     */
    function facetwp_indexer_query_args( $args ) {
        $args['lang'] = ''; // query posts in all languages
        return $args;
    }


    /**
     * Warn the user that Polylang is inactive
     */
    function admin_notice() {
?>
    <div class="error">
        <p><code>FacetWP - Polylang</code> requires the <a href="<?php echo admin_url(); ?>plugin-install.php?tab=search&s=polylang">Polylang</a> plugin. Please install and/or activate it.</p>
    </div>
<?php
    }


    /**
     * Register dynamic strings
     */
    function register_strings() {
        $facets = FWP()->helper->get_facets();
        $whitelist = array( 'label', 'label_any', 'placeholder' );

        if ( ! empty( $facets ) ) {
            foreach ( $facets as $facet ) {
                foreach ( $whitelist as $k ) {
                    if ( ! empty( $facet[ $k ] ) ) {
                        pll_register_string( 'FacetWP', $facet[ $k ] );
                    }
                }
            }
        }
    }


    /**
     * Handle string translations
     */
    function facetwp_i18n( $string ) {
        $lang = pll_current_language();
        $default = pll_default_language();

        if ( isset( FWP()->facet->http_params['lang'] ) ) {
            $lang = FWP()->facet->http_params['lang'];
        }

        if ( $lang != $default ) {
            return pll_translate_string( $string, $lang );
        }

        return $string;
    }
}


$fwp_polylang = new FWP_Polylang();
7 years ago
<?php
/*
Plugin Name: FacetWP - Polylang
Description: Polylang support for FacetWP
Version: 1.2.1
Author: FacetWP, LLC
Author URI: https://facetwp.com/
GitHub URI: facetwp/facetwp-polylang
*/

defined( 'ABSPATH' ) or exit;

class FWP_Polylang
{

    function __construct() {
        add_action( 'init' , array( $this, 'init' ) );
    }


    /**
     * Intialize
     */
    function init() {

        if ( function_exists( 'FWP' ) && function_exists( 'pll_register_string' ) ) {
            add_action( 'wp_footer', array( $this, 'wp_footer' ), 30 );
            add_action( 'admin_init', array( $this, 'register_strings' ) );

            add_filter( 'facetwp_query_args', array( $this, 'facetwp_query_args' ), 10, 2 );
            add_filter( 'facetwp_indexer_query_args', array( $this, 'facetwp_indexer_query_args' ) );
            add_filter( 'facetwp_render_params', array( $this, 'support_preloader' ) );
            add_filter( 'facetwp_i18n', array( $this, 'facetwp_i18n' ) );
        }
        else {
            add_action( 'admin_notices', array( $this, 'admin_notice' ) );
        }
    }


    /**
     * Put the language into FWP_HTTP
     */
    function wp_footer() {
        if ( function_exists( 'pll_current_language' ) ) {
            $lang = pll_current_language();
            echo "<script>if ('undefined' != typeof FWP_HTTP) FWP_HTTP.lang = '$lang';</script>";
        }
    }


    /**
     * Support FacetWP's preloader (3.0.4+)
     */
    function support_preloader( $params ) {
        if ( isset( $params['is_preload'] ) && function_exists( 'pll_current_language' ) ) {
            $params['http_params']['lang'] = pll_current_language();
        }

        return $params;
    }


    /**
     * Query posts for the current language
     */
    function facetwp_query_args( $args, $class ) {
        if ( isset( $class->http_params['lang'] ) ) {
            $args['lang'] = $class->http_params['lang'];
        }

        return $args;
    }


    /**
     * Index all languages
     */
    function facetwp_indexer_query_args( $args ) {
        $args['lang'] = ''; // query posts in all languages
        return $args;
    }


    /**
     * Warn the user that Polylang is inactive
     */
    function admin_notice() {
?>
    <div class="error">
        <p><code>FacetWP - Polylang</code> requires the <a href="<?php echo admin_url(); ?>plugin-install.php?tab=search&s=polylang">Polylang</a> plugin. Please install and/or activate it.</p>
    </div>
<?php
    }


    /**
     * Register dynamic strings
     */
    function register_strings() {
        $facets = FWP()->helper->get_facets();
        $whitelist = array( 'label', 'label_any', 'placeholder' );

        if ( ! empty( $facets ) ) {
            foreach ( $facets as $facet ) {
                foreach ( $whitelist as $k ) {
                    if ( ! empty( $facet[ $k ] ) ) {
                        pll_register_string( 'FacetWP', $facet[ $k ] );
                    }
                }
            }
        }
    }


    /**
     * Handle string translations
     */
    function facetwp_i18n( $string ) {
        $lang = pll_current_language();
        $default = pll_default_language();

        if ( isset( FWP()->facet->http_params['lang'] ) ) {
            $lang = FWP()->facet->http_params['lang'];
        }

        if ( $lang != $default ) {
            return pll_translate_string( $string, $lang );
        }

        return $string;
    }
}


$fwp_polylang = new FWP_Polylang();
8 years ago
<?php

function fwp_index_resumes( $args ) {
    $args['post_type'] = (array) get_post_types();
    $args['post_type'][] = 'resume';
    return $args;
}
add_filter( 'facetwp_indexer_query_args', 'fwp_index_resumes' );