Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
SettingsService
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 1
 initialize
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3namespace NewfoldLabs\WP\Module\Onboarding\Services;
4
5use NewfoldLabs\WP\Module\Onboarding\Data\Config;
6use NewfoldLabs\WP\Module\Onboarding\Data\Options;
7use NewfoldLabs\WP\Module\Onboarding\WP_Config;
8
9class SettingsService {
10
11    /**
12     * Initialize WordPress Options, Permalinks and Configuration.
13     *
14     * @return void
15     */
16    public static function initialize(): void {
17        if ( \get_option( Options::get_option_name( 'settings_initialized' ), false ) ) {
18            return;
19        }
20
21        // Update wp_options
22        $init_options = Options::get_initialization_options();
23        foreach ( $init_options as $option_key => $option_value ) {
24            \update_option( Options::get_option_name( $option_key, false ), $option_value );
25        }
26        // Can't be part of initialization constants as they are static.
27        \update_option( Options::get_option_name( 'start_date' ), gmdate( 'U' ) );
28
29        // Flush permalinks
30        flush_rewrite_rules();
31
32        // Add constants to the WordPress configuration (wp-config.php)
33        $wp_config_constants = Config::get_wp_config_initialization_constants();
34        $wp_config           = new WP_Config();
35        foreach ( $wp_config_constants as $constant_key => $constant_value ) {
36            if ( $wp_config->constant_exists( $constant_key ) ) {
37                $wp_config->update_constant( $constant_key, $constant_value );
38                continue;
39            }
40            $wp_config->add_constant( $constant_key, $constant_value );
41        }
42
43        \update_option( Options::get_option_name( 'settings_initialized' ), true );
44    }
45}