-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1531 from 10up/feature/comments-indexable
Add a Comments Indexable
- Loading branch information
Showing
15 changed files
with
5,325 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
/** | ||
* Comments feature | ||
* | ||
* @since 3.6.0 | ||
* @package elasticpress | ||
*/ | ||
|
||
namespace ElasticPress\Feature\Comments; | ||
|
||
use ElasticPress\Feature as Feature; | ||
use ElasticPress\Indexables as Indexables; | ||
use ElasticPress\Indexable as Indexable; | ||
use ElasticPress\FeatureRequirementsStatus as FeatureRequirementsStatus; | ||
|
||
/** | ||
* Comments feature class | ||
*/ | ||
class Comments extends Feature { | ||
|
||
/** | ||
* Initialize feature, setting it's config | ||
* | ||
* @since 3.6.0 | ||
*/ | ||
public function __construct() { | ||
$this->slug = 'comments'; | ||
$this->title = esc_html__( 'Comments', 'elasticpress' ); | ||
$this->requires_install_reindex = true; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Setup search functionality | ||
* | ||
* @since 3.6.0 | ||
*/ | ||
public function setup() { | ||
Indexables::factory()->register( new Indexable\Comment\Comment() ); | ||
|
||
add_action( 'init', [ $this, 'search_setup' ] ); | ||
} | ||
|
||
/** | ||
* Setup search integration | ||
* | ||
* @since 3.6.0 | ||
*/ | ||
public function search_setup() { | ||
$admin_integration = apply_filters( 'ep_admin_wp_query_integration', false ); | ||
|
||
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { | ||
/** | ||
* Filter to integrate with admin ajax queries | ||
* | ||
* @hook ep_ajax_wp_query_integration | ||
* @param {bool} $integrate True to integrate | ||
* @return {bool} New value | ||
*/ | ||
if ( ! apply_filters( 'ep_ajax_wp_query_integration', false ) ) { | ||
return; | ||
} else { | ||
$admin_integration = true; | ||
} | ||
} | ||
|
||
if ( is_admin() && ! $admin_integration ) { | ||
return; | ||
} | ||
|
||
add_filter( 'ep_elasticpress_enabled', [ $this, 'integrate_search_queries' ], 10, 2 ); | ||
} | ||
|
||
/** | ||
* Output feature box summary | ||
* | ||
* @since 3.6.0 | ||
*/ | ||
public function output_feature_box_summary() { | ||
?> | ||
<p><?php esc_html_e( 'Improve comment search relevancy and query performance.', 'elasticpress' ); ?></p> | ||
<?php | ||
} | ||
|
||
/** | ||
* Output feature box long text | ||
* | ||
* @since 3.6.0 | ||
*/ | ||
public function output_feature_box_long() { | ||
?> | ||
<p><?php esc_html_e( 'This feature will empower your website to overcome traditional WordPress comment search and query limitations that can present themselves at scale.', 'elasticpress' ); ?></p> | ||
<?php | ||
} | ||
|
||
/** | ||
* Enable integration on search queries | ||
* | ||
* @param bool $enabled Whether EP is enabled | ||
* @param \WP_Comment_Query $query Current query object. | ||
* @since 3.6.0 | ||
* @return bool | ||
*/ | ||
public function integrate_search_queries( $enabled, $query ) { | ||
if ( ! is_a( $query, 'WP_Comment_Query' ) ) { | ||
return $enabled; | ||
} | ||
|
||
if ( isset( $query->query_vars['ep_integrate'] ) && false === $query->query_vars['ep_integrate'] ) { | ||
$enabled = false; | ||
} elseif ( ! empty( $query->query_vars['search'] ) ) { | ||
$enabled = true; | ||
} | ||
|
||
return $enabled; | ||
} | ||
|
||
/** | ||
* Determine feature reqs status | ||
* | ||
* @since 3.6.0 | ||
* @return FeatureRequirementsStatus | ||
*/ | ||
public function requirements_status() { | ||
$status = new FeatureRequirementsStatus( 1 ); | ||
|
||
return $status; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.