Skip to content

Commit

Permalink
Refactor get_defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Mar 10, 2024
1 parent 8c40a41 commit 4f614d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
10 changes: 9 additions & 1 deletion src/Installation/Activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ public function set_first_install_options(): void {
\add_option( 'gtmkit_initial_version', GTMKIT_VERSION, '', false );
\update_option( 'gtmkit_version', GTMKIT_VERSION, false );

Options::init()->set( Options::get_defaults( true ), true );
$map = Options::get_defaults();
$defaults = [];
foreach ( $map as $group => $settings ) {
foreach ( $settings as $key => $option ) {
$defaults[ $group ][ $key ] = $option['default'];
}
}

Options::init()->set( $defaults, true );

// Add transient to trigger redirect to the Setup Wizard.
\set_transient( 'gtmkit_activation_redirect', true, 30 );
Expand Down
14 changes: 1 addition & 13 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,12 @@ public function pre_update_option( $new_value, $old_value ): ?array {
/**
* The default options.
*
* @param bool $flat Flattens the default settings for first install.
*
* @return array
*/
public static function get_defaults( bool $flat = false ): array {
public static function get_defaults(): array {

$map = self::$map;

if ( $flat === true ) {
$defaults = [];
foreach ( $map as $group => $settings ) {
foreach ( $settings as $key => $option ) {
$defaults[ $group ][ $key ] = $option['default'];
}
}
return $defaults;
}

return $map;
}

Expand Down

0 comments on commit 4f614d3

Please sign in to comment.