Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the plugin compatible with EP 5 #81

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions includes/classes/Feature/BooleanSearchOperators.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,25 @@ public function output_feature_box_summary() {
* Output feature box long
*/
public function output_feature_box_long() {
if ( ! defined( 'EP_VERSION' ) || version_compare( EP_VERSION, '5.0.0', '<' ) ) {
echo wp_kses( $this->get_instructions(), 'ep-html' );
return;
}

_doing_it_wrong(
__METHOD__,
esc_html__( 'Settings are now generated via the set_settings_schema() method.' ),
'ElasticPress Labs 2.2.0'
);
}

/**
* Generate the instructions text
*
* @since 2.2.0
*/
public function get_instructions() {
ob_start();
?>
<p><?php esc_html_e( 'Allows users to search using the following boolean operators:', 'elasticpress-labs' ); ?></p>
<ul>
Expand Down Expand Up @@ -403,5 +422,21 @@ public function output_feature_box_long() {
</li>
</ul>
<?php
return ob_get_clean();
}

/**
* Set the `settings_schema` attribute
*
* @since 2.2.0
*/
public function set_settings_schema() {
$this->settings_schema = [
[
'key' => 'instructions',
'label' => $this->get_instructions(),
'type' => 'markup',
],
];
}
}
32 changes: 29 additions & 3 deletions includes/classes/Feature/CoAuthorsPlus.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function __construct() {

$this->is_protected_content_feature_active = $protected_content_feature && $protected_content_feature->is_active();

$this->requires_feature = 'protected_content';

parent::__construct();
}

Expand Down Expand Up @@ -202,9 +204,33 @@ public function output_feature_box_summary() {
* @since 1.1.0
*/
public function output_feature_box_long() {
?>
<p><?php echo wp_kses_post( __( 'If using the Co-Authors Plus plugin and the Protected Content feature, enable this feature to visit the Admin Post List screen by Author name <code>wp-admin/edit.php?author_name=&lt;name&gt;</code> and see correct results.', 'elasticpress-labs' ) ); ?></p>
<?php
if ( ! defined( 'EP_VERSION' ) || version_compare( EP_VERSION, '5.0.0', '<' ) ) {
?>
<p><?php echo wp_kses_post( __( 'If using the Co-Authors Plus plugin and the Protected Content feature, enable this feature to visit the Admin Post List screen by Author name <code>wp-admin/edit.php?author_name=&lt;name&gt;</code> and see correct results.', 'elasticpress-labs' ) ); ?></p>
<?php
return;
}

_doing_it_wrong(
__METHOD__,
esc_html__( 'Settings are now generated via the set_settings_schema() method.' ),
'ElasticPress Labs 2.2.0'
);
}

/**
* Set the `settings_schema` attribute
*
* @since 2.2.0
*/
public function set_settings_schema() {
$this->settings_schema = [
[
'key' => 'instructions',
'label' => '<p>' . __( 'If using the Co-Authors Plus plugin and the Protected Content feature, enable this feature to visit the Admin Post List screen by Author name <code>wp-admin/edit.php?author_name=&lt;name&gt;</code> and see correct results.', 'elasticpress-labs' ) . '</p>',
'type' => 'markup',
],
];
}

/**
Expand Down
119 changes: 76 additions & 43 deletions includes/classes/Feature/MetaKeyPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,54 +85,87 @@ public function setup() {
* Display field settings on the Dashboard.
*/
public function output_feature_box_settings() {
$settings = $this->get_settings();

if ( ! $settings ) {
$settings = [];
}
if ( ! defined( 'EP_VERSION' ) || version_compare( EP_VERSION, '5.0.0', '<' ) ) {
$settings = $this->get_settings();

$settings = wp_parse_args( $settings, $this->default_settings );
if ( ! $settings ) {
$settings = [];
}

?>
<div class="field js-toggle-feature" data-feature="<?php echo esc_attr( $this->slug ); ?>">
<div class="field-name status">
<label for="meta_key_allow_pattern">
<?php esc_html_e( 'Allow patterns', 'elasticpress-labs' ); ?>
</label>
$settings = wp_parse_args( $settings, $this->default_settings );

?>
<div class="field js-toggle-feature" data-feature="<?php echo esc_attr( $this->slug ); ?>">
<div class="field-name status">
<label for="meta_key_allow_pattern">
<?php esc_html_e( 'Allow patterns', 'elasticpress-labs' ); ?>
</label>
</div>
<div class="input-wrap">
<textarea
class="setting-field large-text code"
id="meta_key_allow_pattern"
rows="4"
name="settings[meta_key_allow_pattern]"
><?php echo empty( $settings['meta_key_allow_pattern'] ) ? '' : esc_textarea( $settings['meta_key_allow_pattern'] ); ?></textarea>
<p class="field-description">
<?php esc_html_e( 'Separate multiple regular expressions with line breaks.', 'elasticpress-labs' ); ?>
<?php esc_html_e( 'Include the weight of the pattern adding a pipe (|) followed by a number. Example: /^[a-z]/|5', 'elasticpress-labs' ); ?>
</p>
</div>
</div>
<div class="input-wrap">
<textarea
class="setting-field large-text code"
id="meta_key_allow_pattern"
rows="4"
name="settings[meta_key_allow_pattern]"
><?php echo empty( $settings['meta_key_allow_pattern'] ) ? '' : esc_textarea( $settings['meta_key_allow_pattern'] ); ?></textarea>
<p class="field-description">
<?php esc_html_e( 'Separate multiple regular expressions with line breaks.', 'elasticpress-labs' ); ?>
<?php esc_html_e( 'Include the weight of the pattern adding a pipe (|) followed by a number. Example: /^[a-z]/|5', 'elasticpress-labs' ); ?>
</p>
</div>
</div>

<div class="field js-toggle-feature" data-feature="<?php echo esc_attr( $this->slug ); ?>">
<div class="field-name status">
<label for="meta_key_deny_pattern">
<?php esc_html_e( 'Deny patterns', 'elasticpress-labs' ); ?>
</label>
</div>
<div class="input-wrap">
<textarea
class="setting-field large-text code"
id="meta_key_deny_pattern"
rows="4"
name="settings[meta_key_deny_pattern]"
><?php echo empty( $settings['meta_key_deny_pattern'] ) ? '' : esc_textarea( $settings['meta_key_deny_pattern'] ); ?></textarea>
<p class="field-description">
<?php esc_html_e( 'Separate multiple regular expressions with line breaks.', 'elasticpress-labs' ); ?>
</p>
<div class="field js-toggle-feature" data-feature="<?php echo esc_attr( $this->slug ); ?>">
<div class="field-name status">
<label for="meta_key_deny_pattern">
<?php esc_html_e( 'Deny patterns', 'elasticpress-labs' ); ?>
</label>
</div>
<div class="input-wrap">
<textarea
class="setting-field large-text code"
id="meta_key_deny_pattern"
rows="4"
name="settings[meta_key_deny_pattern]"
><?php echo empty( $settings['meta_key_deny_pattern'] ) ? '' : esc_textarea( $settings['meta_key_deny_pattern'] ); ?></textarea>
<p class="field-description">
<?php esc_html_e( 'Separate multiple regular expressions with line breaks.', 'elasticpress-labs' ); ?>
</p>
</div>
</div>
</div>
<?php
<?php
return;
}

_doing_it_wrong(
__METHOD__,
esc_html__( 'Settings are now generated via the set_settings_schema() method.' ),
'ElasticPress Labs 2.2.0'
);
}

/**
* Set the `settings_schema` attribute
*
* @since 2.2.0
*/
public function set_settings_schema() {
$this->settings_schema = [
[
'default' => '',
'help' => __( '<p>Separate multiple regular expressions with line breaks.</p><p>Include the weight of the pattern adding a pipe (|) followed by a number. Example: /^[a-z]/|5</p>', 'elasticpress-labs' ),
'key' => 'meta_key_allow_pattern',
'label' => __( 'Allow patterns', 'elasticpress-labs' ),
'type' => 'textarea',
],
[
'default' => '',
'help' => __( 'Separate multiple regular expressions with line breaks.', 'elasticpress-labs' ),
'key' => 'meta_key_deny_pattern',
'label' => __( 'Deny patterns', 'elasticpress-labs' ),
'type' => 'textarea',
],
];
}

/**
Expand Down
96 changes: 65 additions & 31 deletions includes/classes/Feature/SearchAlgorithm.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,43 +75,77 @@ public function setup() {
* Display field settings on the Dashboard.
*/
public function output_feature_box_settings() {
$settings = $this->get_settings();
if ( ! defined( 'EP_VERSION' ) || version_compare( EP_VERSION, '5.0.0', '<' ) ) {
$settings = $this->get_settings();

if ( ! $settings ) {
$settings = [];
}
if ( ! $settings ) {
$settings = [];
}

$settings = wp_parse_args( $settings, $this->default_settings );
$settings = wp_parse_args( $settings, $this->default_settings );

?>
<div class="field">
<div class="field-name status">
<?php esc_html_e( 'Version', 'elasticpress-labs' ); ?>
</div>
?>
<div class="field">
<div class="field-name status">
<?php esc_html_e( 'Version', 'elasticpress-labs' ); ?>
</div>

<div class="input-wrap">
<?php
$search_algorithms = \ElasticPress\SearchAlgorithms::factory()->get_all();
foreach ( $search_algorithms as $search_algorithm ) {
?>
<label>
<input
name="settings[search_algorithm_version]"
type="radio"
<?php checked( $settings['search_algorithm_version'], $search_algorithm->get_slug() ); ?>
value="<?php echo esc_attr( $search_algorithm->get_slug() ); ?>">
<?php echo esc_html( $search_algorithm->get_name() ); ?>
</label>
<p class="field-description">
<?php echo wp_kses_post( $search_algorithm->get_description() ); ?>
</p>
<br>
<div class="input-wrap">
<?php
}
?>
$search_algorithms = \ElasticPress\SearchAlgorithms::factory()->get_all();
foreach ( $search_algorithms as $search_algorithm ) {
?>
<label>
<input
name="settings[search_algorithm_version]"
type="radio"
<?php checked( $settings['search_algorithm_version'], $search_algorithm->get_slug() ); ?>
value="<?php echo esc_attr( $search_algorithm->get_slug() ); ?>">
<?php echo esc_html( $search_algorithm->get_name() ); ?>
</label>
<p class="field-description">
<?php echo wp_kses_post( $search_algorithm->get_description() ); ?>
</p>
<br>
<?php
}
?>
</div>
</div>
</div>
<?php
<?php
return;
}

_doing_it_wrong(
__METHOD__,
esc_html__( 'Settings are now generated via the set_settings_schema() method.' ),
'ElasticPress Labs 2.2.0'
);
}

/**
* Set the `settings_schema` attribute
*
* @since 2.2.0
*/
public function set_settings_schema() {
$search_algorithms = \ElasticPress\SearchAlgorithms::factory()->get_all();
$options = [];

foreach ( $search_algorithms as $search_algorithm ) {
$options[] = [
'label' => $search_algorithm->get_name() . '<br><small>' . $search_algorithm->get_description() . '</small>',
'value' => $search_algorithm->get_slug(),
];
}

$this->settings_schema[] = [
'default' => '3.5',
'key' => 'search_algorithm_version',
'label' => __( 'Version', 'elasticpress-labs' ),
'options' => $options,
'type' => 'radio',
];
}

/**
Expand Down
34 changes: 27 additions & 7 deletions includes/functions/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function setup() {
// Hook to allow async or defer on asset loading.
add_filter( 'script_loader_tag', $n( 'script_loader_tag' ), 10, 2 );

add_action( 'plugins_loaded', $n( 'maybe_load_features' ) );
add_action( 'plugins_loaded', $n( 'maybe_load_features' ), 11 );

add_filter( 'ep_user_register_feature', '__return_false' );

Expand Down Expand Up @@ -201,12 +201,32 @@ function maybe_load_features() {
return;
}

// Include your class file.
require_once ELASTICPRESS_LABS_INC . 'classes/Feature/ElasticPressLabs.php';
// Register your feature in ElasticPress.
\ElasticPress\Features::factory()->register_feature(
new \ElasticPressLabs()
);
if ( ! defined( 'EP_VERSION' ) || version_compare( EP_VERSION, '5.0.0', '<' ) ) {
// Include your class file.
require_once ELASTICPRESS_LABS_INC . 'classes/Feature/ElasticPressLabs.php';
\ElasticPress\Features::factory()->register_feature(
new \ElasticPressLabs()
);
return;
}

$sep = DIRECTORY_SEPARATOR;
$features_dir = ELASTICPRESS_LABS_PATH . "includes{$sep}classes{$sep}Feature{$sep}";

foreach ( glob( "{$features_dir}*.php" ) as $filename ) {
if ( realpath( $filename ) === __FILE__ ) {
continue;
}

$class_name = 'ElasticPressLabs\Feature\\' . basename( $filename, '.php' );

if ( class_exists( $class_name ) ) {
$subfeature = new $class_name();

\ElasticPress\Features::factory()->register_feature( $subfeature );
$subfeature->setup();
}
}
}

/**
Expand Down