ldc-poule-et-toque/content/plugins/elasticpress/includes/classes/Feature/Terms/Terms.php
2021-04-12 15:54:29 +02:00

110 lines
2.4 KiB
PHP

<?php
/**
* Terms feature
*
* @since 3.1
* @package elasticpress
*/
namespace ElasticPress\Feature\Terms;
use ElasticPress\Feature as Feature;
use ElasticPress\Indexables as Indexables;
use ElasticPress\Indexable as Indexable;
use ElasticPress\FeatureRequirementsStatus as FeatureRequirementsStatus;
/**
* Terms feature class
*/
class Terms extends Feature {
/**
* Initialize feature, setting it's config
*
* @since 3.1
*/
public function __construct() {
$this->slug = 'terms';
$this->title = esc_html__( 'Terms', 'elasticpress' );
$this->requires_install_reindex = true;
parent::__construct();
}
/**
* Setup search functionality
*
* @since 3.1
*/
public function setup() {
Indexables::factory()->register( new Indexable\Term\Term() );
add_action( 'init', [ $this, 'search_setup' ] );
}
/**
* Setup search integration
*
* @since 3.1
*/
public function search_setup() {
add_filter( 'ep_elasticpress_enabled', [ $this, 'integrate_search_queries' ], 10, 2 );
}
/**
* Output feature box summary
*
* @since 3.1
*/
public function output_feature_box_summary() {
?>
<p><?php esc_html_e( 'Improve WP_Term_Query relevancy and query performance. This feature is only needed if you are using WP_Term_Query directly.', 'elasticpress' ); ?></p>
<?php
}
/**
* Output feature box long text
*
* @since 3.1
*/
public function output_feature_box_long() {
?>
<p><?php esc_html_e( 'This feature will empower your website to overcome traditional WordPress term search and query limitations that can present themselves at scale.', 'elasticpress' ); ?></p>
<?php
}
/**
* Enable integration on search queries
*
* @param bool $enabled Whether EP is enabled
* @param \WP_Term_Query $query Current query object.
* @since 3.1
* @return bool
*/
public function integrate_search_queries( $enabled, $query ) {
if ( ! is_a( $query, 'WP_Term_Query' ) ) {
return $enabled;
}
if ( isset( $query->query_vars['ep_integrate'] ) && false === $query->query_vars['ep_integrate'] ) {
$enabled = false;
} elseif ( ! empty( $query->query_vars['search'] ) ) {
$enabled = true;
}
return $enabled;
}
/**
* Determine feature reqs status
*
* @since 3.1
* @return FeatureRequirementsStatus
*/
public function requirements_status() {
$status = new FeatureRequirementsStatus( 1 );
return $status;
}
}