PluginProbe
ElasticPress / 4.5.2
ElasticPress v4.5.2
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / includes / classes / Feature / Terms / Terms.php

Terms.php in ElasticPress 4.5.2, at includes/classes/Feature/Terms/Terms.php

123 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Terms feature
4 *
5 * @since 3.1
6 * @package elasticpress
7 */
8
9 namespace ElasticPress\Feature\Terms;
10
11 use ElasticPress\Feature as Feature;
12 use ElasticPress\Indexables as Indexables;
13 use ElasticPress\Indexable as Indexable;
14 use ElasticPress\FeatureRequirementsStatus as FeatureRequirementsStatus;
15
16 /**
17 * Terms feature class
18 */
19 class Terms extends Feature {
20
21 /**
22 * Initialize feature, setting it's config
23 *
24 * @since 3.1
25 */
26 public function __construct() {
27 $this->slug = 'terms';
28
29 $this->title = esc_html__( 'Terms', 'elasticpress' );
30
31 $this->summary = __( 'Improve WP_Term_Query relevancy and query performance. This feature is only needed if you are using WP_Term_Query directly.', 'elasticpress' );
32
33 $this->docs_url = __( 'https://elasticpress.zendesk.com/hc/en-us/articles/360050447492-Configuring-ElasticPress-via-the-Plugin-Dashboard#terms', 'elasticpress' );
34
35 $this->requires_install_reindex = true;
36
37 Indexables::factory()->register( new Indexable\Term\Term(), false );
38
39 parent::__construct();
40 }
41
42 /**
43 * Setup search functionality
44 *
45 * @since 3.1
46 */
47 public function setup() {
48 Indexables::factory()->activate( 'term' );
49
50 add_action( 'init', [ $this, 'search_setup' ] );
51 }
52
53 /**
54 * Setup search integration
55 *
56 * @since 3.1
57 */
58 public function search_setup() {
59 add_filter( 'ep_elasticpress_enabled', [ $this, 'integrate_search_queries' ], 10, 2 );
60 add_filter( 'ep_term_fuzziness_arg', [ $this, 'set_admin_terms_search_fuzziness' ] );
61 }
62
63 /**
64 * Output feature box long text
65 *
66 * @since 3.1
67 */
68 public function output_feature_box_long() {
69 ?>
70 <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>
71 <?php
72 }
73
74 /**
75 * Enable integration on search queries
76 *
77 * @param bool $enabled Whether EP is enabled
78 * @param \WP_Term_Query $query Current query object.
79 * @since 3.1
80 * @return bool
81 */
82 public function integrate_search_queries( $enabled, $query ) {
83 if ( ! is_a( $query, 'WP_Term_Query' ) ) {
84 return $enabled;
85 }
86
87 if ( isset( $query->query_vars['ep_integrate'] ) && ! filter_var( $query->query_vars['ep_integrate'], FILTER_VALIDATE_BOOLEAN ) ) {
88 $enabled = false;
89 } elseif ( ! empty( $query->query_vars['search'] ) ) {
90 $enabled = true;
91 }
92
93 return $enabled;
94 }
95
96 /**
97 * Determine feature reqs status
98 *
99 * @since 3.1
100 * @return FeatureRequirementsStatus
101 */
102 public function requirements_status() {
103 $status = new FeatureRequirementsStatus( 1 );
104
105 return $status;
106 }
107
108 /**
109 * Change fuzziness level for terms search in admin
110 *
111 * @param {int} $fuzziness Amount of fuzziness to factor into search
112 * @since 3.6.4
113 * @return int
114 */
115 public function set_admin_terms_search_fuzziness( $fuzziness ) {
116 if ( is_admin() ) {
117 $fuzziness = 0;
118 }
119 return $fuzziness;
120 }
121
122 }
123