Skip to content

Commit

Permalink
fix(settings): get_setting method
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo committed Nov 16, 2023
1 parent 56aaa26 commit bb1c697
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions includes/class-newspack-popups-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,20 @@ function( $setting ) use ( $section, $key ) {
* @param string $key Key name.
*/
public static function get_setting( $key ) {
return get_option( $key, true );
$settings = self::get_settings();
foreach ( $settings as $setting ) {
if ( $key === $setting['key'] ) {
return $setting['value'];
}
}
return new \WP_Error(
'newspack_popups_settings_error',
sprintf(
// Translators: Invalid settings key error.
__( 'Invalid settings key: %s', 'newpack-popups' ),
$key
)
);
}

/**
Expand Down Expand Up @@ -231,7 +244,7 @@ public static function get_settings( $assoc = false, $get_segments = false ) {

$settings_list = [
[
'description' => __( 'Donor Settings', 'newspack-ads' ),
'description' => __( 'Donor Settings', 'newspack-popups' ),
'help' => __( 'Configure when readers are considered donors.', 'newspack-ads' ),
'section' => 'donor_settings',
'key' => 'active',
Expand Down Expand Up @@ -339,6 +352,9 @@ function( $acc, $item ) {
$settings_list = array_reduce(
$settings_list,
function ( $carry, $item ) {
if ( ! isset( $carry[ $item['section'] ] ) ) {
$carry[ $item['section'] ] = [];
}
$carry[ $item['section'] ][] = $item;
return $carry;
},
Expand Down

0 comments on commit bb1c697

Please sign in to comment.