PluginProbe
ElasticPress / 4.6.0
ElasticPress v4.6.0
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 / Users / Users.php

Users.php in ElasticPress 4.6.0, at includes/classes/Feature/Users/Users.php

147 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Users feature
4 *
5 * @since 1.9
6 * @package elasticpress
7 */
8
9 namespace ElasticPress\Feature\Users;
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 use ElasticPress\Utils as Utils;
16
17 /**
18 * Users feature class
19 */
20 class Users extends Feature {
21 /**
22 * Initialize feature setting it's config
23 *
24 * @since 3.0
25 */
26 public function __construct() {
27 $this->slug = 'users';
28
29 $this->title = esc_html__( 'Users', 'elasticpress' );
30
31 $this->summary = __( 'Improve user search relevancy and query performance.', 'elasticpress' );
32
33 $this->docs_url = __( 'https://elasticpress.zendesk.com/hc/en-us/articles/360050447492-Configuring-ElasticPress-via-the-Plugin-Dashboard#users', 'elasticpress' );
34
35 $this->requires_install_reindex = true;
36
37 Indexables::factory()->register( new Indexable\User\User(), false );
38
39 parent::__construct();
40 }
41
42 /**
43 * Hook search functionality
44 *
45 * @since 3.0
46 */
47 public function setup() {
48 Indexables::factory()->activate( 'user' );
49
50 add_action( 'init', [ $this, 'search_setup' ] );
51 add_filter( 'ep_admin_notices', [ $this, 'add_migration_notice' ] );
52 }
53
54 /**
55 * Setup feature on each page load
56 *
57 * @since 3.0
58 */
59 public function search_setup() {
60 add_filter( 'ep_elasticpress_enabled', [ $this, 'integrate_search_queries' ], 10, 2 );
61 }
62
63 /**
64 * Output feature box long text
65 *
66 * @since 3.0
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 user search and query limitations that can present themselves at scale.', 'elasticpress' ); ?></p>
71 <p><?php esc_html_e( 'Be aware that storing user data may bound you to certain legal obligations depending on your local government regulations.', 'elasticpress' ); ?></p>
72 <?php
73 }
74
75 /**
76 * Enable integration on search queries
77 *
78 * @param bool $enabled Whether EP is enabled
79 * @param WP_User_Query $query Current query object.
80 * @since 3.0
81 * @return bool
82 */
83 public function integrate_search_queries( $enabled, $query ) {
84 if ( ! is_a( $query, 'WP_User_Query' ) ) {
85 return $enabled;
86 }
87
88 if ( isset( $query->query_vars['ep_integrate'] ) && ! filter_var( $query->query_vars['ep_integrate'], FILTER_VALIDATE_BOOLEAN ) ) {
89 $enabled = false;
90 } elseif ( ! empty( $query->query_vars['search'] ) ) {
91 $enabled = true;
92 }
93
94 return $enabled;
95 }
96
97 /**
98 * Determine feature reqs status
99 *
100 * @since 2.2
101 * @return FeatureRequirementsStatus
102 */
103 public function requirements_status() {
104 $status = new FeatureRequirementsStatus( 1 );
105
106 $status->message = [
107 sprintf(
108 /* translators: ElasticPress Labs URL */
109 __( 'Due to the potential for inadvertently exposing user data on non-ElasticPress.io installations, the Users Feature will be moving to the <a href="%s">ElasticPress Labs</a> plugin as of ElasticPress 5.0.', 'elasticpress' ),
110 'https://github.com/10up/ElasticPressLabs'
111 ),
112 ];
113
114 return $status;
115 }
116
117 /**
118 * Display a notice about the feature migration to ElasticPress Labs
119 *
120 * @since 4.5.0
121 * @param array $notices Notices array
122 * @return array
123 */
124 public function add_migration_notice( $notices ) {
125 if ( ! current_user_can( Utils\get_capability() ) ) {
126 return $notices;
127 }
128
129 // Dismissed.
130 if ( Utils\get_option( 'ep_hide_users_migration_notice', false ) ) {
131 return $notices;
132 }
133
134 $notices['users_migration'] = [
135 'html' => sprintf(
136 /* translators: ElasticPress Labs URL */
137 __( 'Due to the potential for inadvertently exposing user data on non-ElasticPress.io installations, the Users Feature will be moving to the <a href="%s">ElasticPress Labs</a> plugin as of ElasticPress 5.0.', 'elasticpress' ),
138 'https://github.com/10up/ElasticPressLabs'
139 ),
140 'type' => 'warning',
141 'dismiss' => true,
142 ];
143
144 return $notices;
145 }
146 }
147