PluginProbe
ElasticPress / 5.0.2
ElasticPress v5.0.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 5.0.2, at includes/classes/Feature/Terms/Terms.php

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