PluginProbe
ElasticPress / 4.3.1
ElasticPress v4.3.1
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.3.1, at includes/classes/Feature/Terms/Terms.php

121 lines 2.8 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 parent::__construct();
38 }
39
40 /**
41 * Setup search functionality
42 *
43 * @since 3.1
44 */
45 public function setup() {
46 Indexables::factory()->register( new Indexable\Term\Term() );
47
48 add_action( 'init', [ $this, 'search_setup' ] );
49 }
50
51 /**
52 * Setup search integration
53 *
54 * @since 3.1
55 */
56 public function search_setup() {
57 add_filter( 'ep_elasticpress_enabled', [ $this, 'integrate_search_queries' ], 10, 2 );
58 add_filter( 'ep_term_fuzziness_arg', [ $this, 'set_admin_terms_search_fuzziness' ] );
59 }
60
61 /**
62 * Output feature box long text
63 *
64 * @since 3.1
65 */
66 public function output_feature_box_long() {
67 ?>
68 <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>
69 <?php
70 }
71
72 /**
73 * Enable integration on search queries
74 *
75 * @param bool $enabled Whether EP is enabled
76 * @param \WP_Term_Query $query Current query object.
77 * @since 3.1
78 * @return bool
79 */
80 public function integrate_search_queries( $enabled, $query ) {
81 if ( ! is_a( $query, 'WP_Term_Query' ) ) {
82 return $enabled;
83 }
84
85 if ( isset( $query->query_vars['ep_integrate'] ) && ! filter_var( $query->query_vars['ep_integrate'], FILTER_VALIDATE_BOOLEAN ) ) {
86 $enabled = false;
87 } elseif ( ! empty( $query->query_vars['search'] ) ) {
88 $enabled = true;
89 }
90
91 return $enabled;
92 }
93
94 /**
95 * Determine feature reqs status
96 *
97 * @since 3.1
98 * @return FeatureRequirementsStatus
99 */
100 public function requirements_status() {
101 $status = new FeatureRequirementsStatus( 1 );
102
103 return $status;
104 }
105
106 /**
107 * Change fuzziness level for terms search in admin
108 *
109 * @param {int} $fuzziness Amount of fuzziness to factor into search
110 * @since 3.6.4
111 * @return int
112 */
113 public function set_admin_terms_search_fuzziness( $fuzziness ) {
114 if ( is_admin() ) {
115 $fuzziness = 0;
116 }
117 return $fuzziness;
118 }
119
120 }
121