Skip to content
Draft
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
7 changes: 4 additions & 3 deletions abilities/class-ability-update-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ public function execute( $input = null ) {

// Build allowlist of {section}_{field} keys from registered settings,
// and a parallel list of which keys correspond to checkbox fields.
// We need the latter because Settings::sanitize_setting_by_field_type()
// We need the latter because Settings_Sanitizer::sanitize_setting_by_field_type()
// only accepts numeric values for checkboxes (is_numeric() rejects PHP
// booleans), so true/false from a JSON client would otherwise be
// silently coerced to '' instead of 0/1.
$valid_keys = array();
$checkbox_keys = array();
foreach ( $this->plugin->settings->get_fields() as $section => $section_data ) {
$fields = $this->plugin->settings->registry->get_fields();
foreach ( $fields as $section => $section_data ) {
if ( empty( $section_data['fields'] ) || ! is_array( $section_data['fields'] ) ) {
continue;
}
Expand Down Expand Up @@ -147,7 +148,7 @@ public function execute( $input = null ) {
// Run only the incoming keys through Stream's sanitize pipeline so
// values are normalized to their declared field type, then merge over
// the existing options so unrelated keys are preserved.
$sanitized = $this->plugin->settings->sanitize_settings( $filtered );
$sanitized = $this->plugin->settings->sanitizer->sanitize_settings( $filtered, $fields );
$merged = array_merge( $current, $sanitized );

// update_all_setting_values() persists to the correct store and
Expand Down
4 changes: 2 additions & 2 deletions classes/class-admin-purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,14 @@ public function purge_scheduled_action() {
return;
}

$defaults = $this->admin->plugin->settings->get_defaults();
$defaults = $this->admin->plugin->settings->registry->get_defaults();
if ( $this->admin->plugin->is_multisite_network_activated() ) {
$options = wp_parse_args( (array) get_site_option( 'wp_stream_network', array() ), $defaults );
} else {
$options = wp_parse_args( (array) get_option( 'wp_stream', array() ), $defaults );
}

// TTL fallback. Settings::get_defaults() runs every settings field
// TTL fallback. Settings_Registry::get_defaults() runs every settings field
// through the `wp_stream_settings_option_fields` filter, which
// Network::get_network_admin_fields() uses to strip the `records_ttl`
// field from the per-site option's defaults set. When this callback runs
Expand Down
2 changes: 1 addition & 1 deletion classes/class-admin-screen-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function render_settings_page() {

$page_description = apply_filters( 'wp_stream_settings_form_description', '' );

$sections = $this->admin->plugin->settings->get_fields();
$sections = $this->admin->plugin->settings->registry->get_fields();
$active_tab = wp_stream_filter_input( INPUT_GET, 'tab' );

$this->admin->plugin->enqueue_asset(
Expand Down
6 changes: 3 additions & 3 deletions classes/class-network.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public function get_settings_translations( $labels ) {
$labels[ $network_key ] = array();
}

foreach ( $this->plugin->settings->get_fields() as $section_slug => $section ) {
foreach ( $this->plugin->settings->registry->get_fields() as $section_slug => $section ) {
foreach ( $section['fields'] as $field ) {
$labels[ $network_key ][ sprintf( '%s_%s', $section_slug, $field['name'] ) ] = $field['title'];
}
Expand Down Expand Up @@ -395,14 +395,14 @@ public function network_options_action() {

$value = array();
$posted_options = isset( $_POST[ $option ] ) && is_array( $_POST[ $option ] ) ? wp_unslash( $_POST[ $option ] ) : array();
$sections = $this->plugin->settings->get_fields();
$sections = $this->plugin->settings->registry->get_fields();

foreach ( $sections as $section_name => $section ) {
foreach ( $section['fields'] as $field_idx => $field ) {
$option_key = $section_name . '_' . $field['name'];

if ( isset( $posted_options[ $option_key ] ) ) {
$value[ $option_key ] = $this->plugin->settings->sanitize_setting_by_field_type( $posted_options[ $option_key ], $field['type'] );
$value[ $option_key ] = $this->plugin->settings->sanitizer->sanitize_setting_by_field_type( $posted_options[ $option_key ], $field['type'] );
} else {
$value[ $option_key ] = false;
}
Expand Down
Loading
Loading