| 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; |
| 12 |
use ElasticPress\FeatureRequirementsStatus; |
| 13 |
use ElasticPress\Indexable; |
| 14 |
use ElasticPress\Indexables; |
| 15 |
use ElasticPress\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 |
|