Skip to content

Instantly share code, notes, and snippets.

@krugazul
Created March 1, 2019 12:46
Show Gist options
  • Select an option

  • Save krugazul/fe06b489741aeff32516efb92bf9ec7f to your computer and use it in GitHub Desktop.

Select an option

Save krugazul/fe06b489741aeff32516efb92bf9ec7f to your computer and use it in GitHub Desktop.
LSX Search - Enable filters and theme options for a custom taxonomy
<?php
/**
* Custom Taxonomy
*/
class Custom_Taxonomy {
/**
* Holds class instance
*
* @since 1.0.0
*
* @var object Custom_Taxonomy()
*/
protected static $instance = null;
/**
* Initialize the plugin by setting localization, filters, and administration functions.
*
* @since 1.0.0
*
* @access private
*/
private function __construct() {
add_filter( 'lsx_search_post_types_plural', array( $this, 'post_type_plural' ), 100, 1 );
add_filter( 'lsx_search_taxonomies', array( $this, 'enable_taxonomies' ), 100, 1 );
add_filter( 'lsx_search_enabled', array( $this, 'enable_taxonomy_search' ), 100, 1 );
add_filter( 'lsx_search_prefix', array( $this, 'set_search_prefix' ), 100, 1 );
add_action( 'lsx_framework_display_tab_headings_bottom', array( $this, 'display_tab_headings' ), 10, 1 );
add_action( 'lsx_framework_display_tab_bottom', array( $this, 'display_tab_body' ), 10, 1 );
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object Custom_Taxonomy() A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* @param array $post_types
*
* @return array
*/
public function post_type_plural( $post_types = array() ) {
$post_types['custom-taxonomy'] = 'custom-taxonomy';
return $post_types;
}
/**
* Enabled the search for the taxonomies
* @param $prefix
*
* @return string
*/
public function set_search_prefix( $prefix ) {
if ( is_tax( 'custom-taxonomy' ) ) {
$prefix = 'custom-taxonomy_archive';
}
return $prefix;
}
/**
* Enabled the search for the taxonomies
* @param $enabled
*
* @return string
*/
public function enable_taxonomy_search( $enabled ) {
if ( is_tax( 'custom-taxonomy' ) ) {
$enabled = true;
}
return $enabled;
}
public function display_tab_headings( $tab = '' ) {
if ( 'display' === $tab ) { ?>
<li><a href="#ui-custom-taxonomy" class=""><?php esc_html_e( 'Custom Taxonomy', 'your-domain' ); ?></a></li>
<?php }
}
public function display_tab_body( $tab = '' ) {
if ( 'display' === $tab ) { ?>
<div id="ui-custom-taxonomy" class="ui-tab">
<table class="form-table">
<tbody>
<?php do_action( 'lsx_framework_display_tab_content', 'custom-taxonomy' ); ?>
</tbody>
</table>
</div>
<?php }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment