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

Use toggle type for active feature control. #3708

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions includes/classes/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,11 @@ public function get_settings_schema() {
$req_status = $this->requirements_status();

$active = [
'default' => 0 === $req_status->code,
'default' => false,
'key' => 'active',
'label' => __( 'Enabled', 'elasticpress' ),
'requires_sync' => $this->requires_install_reindex,
'type' => 'checkbox',
'type' => 'toggle',
];

$settings_schema = [
Expand Down
9 changes: 4 additions & 5 deletions includes/classes/Feature/Autosuggest/Autosuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,8 @@ protected function maybe_add_epio_settings_schema() {
$status_report_link = defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ? network_admin_url( 'admin.php?page=elasticpress-status-report' ) : admin_url( 'admin.php?page=elasticpress-status-report' );

$this->settings_schema[] = [
'default' => sprintf(
'key' => 'epio',
'label' => sprintf(
/* translators: 1: <a> tag (ElasticPress.io); 2. </a>; 3: <a> tag (KB article); 4. </a>; 5: <a> tag (Site Health Debug Section); 6. </a>; */
__( 'You are directly connected to %1$sElasticPress.io%2$s, ensuring the most performant Autosuggest experience. %3$sLearn more about what this means%4$s or %5$sclick here for debug information%6$s.', 'elasticpress' ),
'<a href="' . esc_url( $epio_link ) . '">',
Expand All @@ -883,9 +884,7 @@ protected function maybe_add_epio_settings_schema() {
'<a href="' . esc_url( $status_report_link ) . '">',
'</a>'
),
'key' => 'epio',
'label' => __( 'Connection', 'elasticpress' ),
'type' => 'markup',
'type' => 'markup',
];
}

Expand Down Expand Up @@ -919,7 +918,7 @@ protected function set_settings_schema() {
$set_in_wp_config = defined( 'EP_AUTOSUGGEST_ENDPOINT' ) && EP_AUTOSUGGEST_ENDPOINT;

$this->settings_schema[] = [
'readonly' => $set_in_wp_config,
'disabled' => $set_in_wp_config,
'help' => $set_in_wp_config ? __( 'This address will be exposed to the public.', 'elasticpress' ) : '',
'key' => 'endpoint_url',
'label' => __( 'Endpoint URL', 'elasticpress' ),
Expand Down
4 changes: 2 additions & 2 deletions includes/classes/Feature/DidYouMean/DidYouMean.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct() {
$this->available_during_installation = true;

$this->default_settings = [
'search_behavior' => false,
'search_behavior' => '0',
];

$this->set_settings_schema();
Expand Down Expand Up @@ -426,7 +426,7 @@ public function the_output( $query = null ) {
protected function set_settings_schema() {
$this->settings_schema = [
[
'default' => false,
'default' => '0',
'key' => 'search_behavior',
'label' => __( 'Search behavior when no result is found', 'elasticpress' ),
'options' => [
Expand Down
24 changes: 7 additions & 17 deletions includes/classes/Feature/InstantResults/InstantResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct() {

$this->default_settings = [
'highlight_tag' => 'mark',
'facets' => 'post_type,category,post_tag',
'facets' => 'post_type,tax-category,tax-post_tag',
'match_type' => 'all',
'term_count' => '1',
'per_page' => get_option( 'posts_per_page', 6 ),
Expand Down Expand Up @@ -954,6 +954,7 @@ public function get_facets_for_admin() {
foreach ( $available_facets as $key => $facet ) {
$facets[ $key ] = array(
'label' => $facet['labels']['admin'],
'value' => $key,
);
}

Expand Down Expand Up @@ -1059,6 +1060,8 @@ public function get_title() : string {
* @since 5.0.0
*/
protected function set_settings_schema() {
$facets = $this->get_facets_for_admin();

$this->settings_schema = [
[
'default' => 'mark',
Expand Down Expand Up @@ -1094,23 +1097,10 @@ protected function set_settings_schema() {
'type' => 'select',
],
[
'default' => 'post_type,category,post_tag',
'default' => 'post_type,tax-category,tax-post_tag',
'key' => 'facets',
'label' => __( 'Filters', 'elasticpress' ),
'options' => [
[
'label' => 'post_type',
'value' => 'post_type',
],
[
'label' => 'category',
'value' => 'category',
],
[
'label' => 'post_tag',
'value' => 'post_tag',
],
],
'options' => array_values( $facets ),
'type' => 'multiple',
],
[
Expand Down Expand Up @@ -1153,7 +1143,7 @@ protected function set_settings_schema() {
'type' => 'hidden',
],
[
'default' => '',
'default' => '0',
'key' => 'search_behavior',
'label' => __( 'Search behavior when no result is found', 'elasticpress' ),
'options' => [
Expand Down
13 changes: 0 additions & 13 deletions includes/classes/Feature/Search/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,19 +922,6 @@ protected function set_settings_schema() {
],
'type' => 'radio',
],
[
'default' => '.ep-autosuggest',
'help' => __( 'Input additional selectors where you would like to include autosuggest separated by a comma. Example: .custom-selector, #custom-id, input[type="text"]', 'elasticpress' ),
'key' => 'autosuggest_selector',
'label' => __( 'Autosuggest Selector', 'elasticpress' ),
'type' => 'text',
],
[
'key' => 'trigger_ga_event',
'help' => __( 'When enabled, a gtag tracking event is fired when an autosuggest result is clicked.', 'elasticpress' ),
'label' => __( 'Google Analytics Events', 'elasticpress' ),
'type' => 'checkbox',
],
[
'default' => 'simple',
'key' => 'synonyms_editor_mode',
Expand Down
7 changes: 3 additions & 4 deletions includes/classes/REST/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ public function get_args() {
case 'radio':
$property['enum'] = array_map( fn( $o ) => $o['value'], $schema['options'] );
break;
case 'multiple':
$property['type'] = 'string';
break;
case 'checkbox':
case 'toggle':
$property['type'] = 'boolean';
break;
case 'checkbox':
case 'multiple':
default:
$property['type'] = 'string';
break;
Expand Down
6 changes: 3 additions & 3 deletions tests/php/TestFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function() {
'key' => 'active',
'label' => __( 'Enabled', 'elasticpress' ),
'requires_sync' => false,
'type' => 'checkbox',
'type' => 'toggle',
],
],
];
Expand Down Expand Up @@ -83,7 +83,7 @@ public function test_get_settings_schema() {
'key' => 'active',
'label' => __( 'Enabled', 'elasticpress' ),
'requires_sync' => false,
'type' => 'checkbox',
'type' => 'toggle',
],
[ 'key' => 'test_1' ],
[ 'key' => 'test_2' ],
Expand Down Expand Up @@ -117,7 +117,7 @@ public function test_ep_feature_settings_schema_filter() {
'key' => 'active',
'label' => __( 'Enabled', 'elasticpress' ),
'requires_sync' => false,
'type' => 'checkbox',
'type' => 'toggle',
],
[ 'key' => 'new_field' ],
],
Expand Down