<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
// boostify_blocks_settings_options
function boostify_blocks_dashboard_settings_options_init()
{
    if (!function_exists('boostify_blocks_get_block_name_enable_init') || !function_exists('boostify_blocks_get_block_type_list')) {
        return;
    }

    // add a new option -- boostify_blocks_enable_disable_options
    if (FALSE === get_option('boostify_blocks_enable_disable_options') && FALSE === update_option('boostify_blocks_enable_disable_options', FALSE)) {
        $boostify_block_status = boostify_blocks_get_block_name_enable_init();
        add_option('boostify_blocks_enable_disable_options', $boostify_block_status);
    }

    // add a new option -- boostify_blocks_settings_options
    if (FALSE === get_option('boostify_blocks_settings_options') && FALSE === update_option('boostify_blocks_settings_options', FALSE)) {
        add_option('boostify_blocks_settings_options', boostify_blocks_get_default_blocks_settings());
    } else {
        // When new fields are added, merge them with existing options.
        // Check if new options exist and merge accordingly. 
        // 01-03-2023
        $hasNewOption = !array_key_exists('customColorPallete', get_option('boostify_blocks_settings_options') ?? []);
        // 
        if ($hasNewOption) {
            update_option('boostify_blocks_settings_options', array_merge(boostify_blocks_get_default_blocks_settings(), get_option('boostify_blocks_settings_options')));
        }
    }
}

add_action('admin_init', 'boostify_blocks_dashboard_settings_options_init');
