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

Features backwards compatibility #3728

Merged
merged 3 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Default implementation of set_settings_schema + textarea fields
  • Loading branch information
felipeelia committed Oct 27, 2023
commit bd5d1404bfcc0fa2e1d78a8dfa3a0050ceef06bd
12 changes: 12 additions & 0 deletions assets/js/features/components/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
RadioControl,
SelectControl,
TextControl,
TextareaControl,
ToggleControl,
} from '@wordpress/components';
import { safeHTML } from '@wordpress/dom';
Expand Down Expand Up @@ -219,6 +220,17 @@ export default ({
/>
);
}
case 'textarea': {
return (
<TextareaControl
help={helpHtml}
label={label}
onChange={onChange}
disabled={isDisabled}
value={value}
/>
);
}
default: {
return (
<TextControl
Expand Down
36 changes: 30 additions & 6 deletions includes/classes/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function output_feature_box_summary() {
*
* @since 3.0
*/
abstract public function output_feature_box_long();
public function output_feature_box_long() {}

/**
* Create feature
Expand Down Expand Up @@ -563,11 +563,7 @@ public function get_json() {
* @return array
*/
public function get_settings_schema() {
if ( [] === $this->settings_schema && method_exists( $this, 'set_settings_schema' ) ) {
$this->set_settings_schema();
}

$req_status = $this->requirements_status();
$this->set_settings_schema();

$active = [
'default' => false,
Expand Down Expand Up @@ -595,4 +591,32 @@ public function get_settings_schema() {
*/
return apply_filters( 'ep_feature_settings_schema', $settings_schema, $this->slug, $this );
}

/**
* Default implementation of `set_settings_schema` basedd on the `default_settings` attribute
*
* @since 5.0.0
*/
protected function set_settings_schema() {
if ( [] === $this->default_settings ) {
return;
}

foreach ( $this->default_settings as $key => $default_value ) {
$type = 'text';
if ( in_array( $default_value, [ '0', '1' ], true ) ) {
$type = 'checkbox';
}
if ( is_bool( $default_value ) ) {
$type = 'toggle';
}

$this->settings_schema[] = [
'default' => $default_value,
'key' => $key,
'label' => $key,
'type' => $type,
];
}
}
}
Loading