Skip to content

Commit

Permalink
Updated Settings API
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaydsouza committed Aug 26, 2024
1 parent 6392a92 commit f972d59
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
13 changes: 10 additions & 3 deletions includes/admin/settings/class-settings-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Settings API wrapper class
*
* @version 2.5.0
* @version 2.5.1
*/
#[\AllowDynamicProperties]
class Settings_API {
Expand All @@ -31,7 +31,7 @@ class Settings_API {
*
* @var string
*/
const VERSION = '2.5.0';
const VERSION = '2.5.1';

/**
* Settings Key.
Expand Down Expand Up @@ -549,7 +549,14 @@ public function admin_init() {
}

// Register the settings into the options table.
register_setting( $settings_key, $settings_key, array( $this, 'settings_sanitize' ) );
register_setting(
$settings_key,
$settings_key,
array(
'sanitize_callback' => array( $this, 'settings_sanitize' ),
'show_in_rest' => true,
)
);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions includes/admin/settings/class-settings-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function callback_checkbox( $args ) {
$checked,
$disabled
);
$html .= ( (bool) $value !== (bool) $default ) ? '<em style="color:orange">' . $this->checkbox_modified_text . '</em>' : '';
$html .= ( (bool) $value !== (bool) $default ) ? '<em style="color:#9B0800">' . $this->checkbox_modified_text . '</em>' : '';
$html .= $this->get_field_description( $args );

/** This filter has been defined in class-settings-api.php */
Expand Down Expand Up @@ -369,15 +369,17 @@ public function callback_multicheck( $args ) {
public function callback_radio( $args ) {
$html = '';

$value = isset( $args['value'] ) ? $args['value'] : $this->get_option( $args['id'], $args['default'] );
$value = isset( $args['value'] ) ? $args['value'] : $this->get_option( $args['id'], $args['default'] );
$disabled = ( ! empty( $args['disabled'] ) || $args['pro'] ) ? ' disabled="disabled"' : '';

foreach ( $args['options'] as $key => $option ) {
$html .= sprintf(
'<input name="%1$s[%2$s]" id="%1$s[%2$s][%3$s]" type="radio" value="%3$s" %4$s /> ',
'<input name="%1$s[%2$s]" id="%1$s[%2$s][%3$s]" type="radio" value="%3$s" %4$s %5$s /> ',
$this->settings_key,
sanitize_key( $args['id'] ),
$key,
checked( $value, $key, false )
checked( $value, $key, false ),
$disabled
);
$html .= sprintf(
'<label for="%1$s[%2$s][%3$s]">%4$s</label> <br />',
Expand Down
4 changes: 2 additions & 2 deletions includes/admin/settings/class-settings-sanitize.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function sanitize_checkbox_field( $value ) {
/**
* Sanitize post_types fields
*
* @param array $value The field value.
* @param array|int $value The field value.
* @return string $value Sanitized value
*/
public function sanitize_posttypes_field( $value ) {
Expand All @@ -167,7 +167,7 @@ public function sanitize_posttypes_field( $value ) {
/**
* Sanitize post_types fields
*
* @param array $value The field value.
* @param array|int $value The field value.
* @return string $value Sanitized value
*/
public function sanitize_taxonomies_field( $value ) {
Expand Down

0 comments on commit f972d59

Please sign in to comment.