<?php
namespace NeoLibraryFull\NeoGlobal; if (!defined("ABSPATH")) { die("neoWP direct access not allowed"); }







// Central file for provisioning all options with defaults that the plugin can set to ensure that the user's WP instance remains streamlined and well-maintained (clean and orderly). The options are cached in RAM for optimized runtime performance, which significantly improves the user's site performance.


\NeoLibraryFull\NeoGlobal\val("neo_global__option_defaults", []); \NeoLibraryFull\NeoGlobal\val("neo_global__option_autoload", []); function _register_option($option_name, $default_value, bool $autoload) { if ($default_value === null) { \NeoLibraryFull\NeoGlobal\throw_global_exception("Option default value cannot be null"); } \NeoLibraryFull\NeoGlobal\val("neo_global__option_defaults")[$option_name] = $default_value; \NeoLibraryFull\NeoGlobal\val("neo_global__option_autoload")[$option_name] = $autoload; }
function get_or_set_option($name, $value = null, $delete = false) {
    static $cache = [];
    if ($delete && $value !== null) { \NeoLibraryFull\NeoGlobal\throw_global_exception("Cannot set and delete an option at the same time"); }
    if ($delete) { delete_option($name); unset($cache[$name]); return; }
    $autoload = \NeoLibraryFull\NeoGlobal\val("neo_global__option_autoload", $name) ?? true;
    if ($value === null) {
        if (isset($cache[$name])) { return $cache[$name]; }
        $option_value = get_option($name);
        $default = \NeoLibraryFull\NeoGlobal\val("neo_global__option_defaults")[$name] ?? null;
        if ($default === null) { \NeoLibraryFull\NeoGlobal\throw_global_exception("Option '$name' not registered with a default value in _global--options.php"); }
        if ($option_value === false) {
            get_or_set_option($name, $default);
            $cache[$name] = $default; return $default;
        }
        if (is_string($default)) { $cache[$name] = $option_value; return $option_value; }
        try {
            $value = \NeoLibraryFull\NeoGlobal\json_decode_better($option_value);
            $cache[$name] = $value; return $value;
        } catch (\NeoLibraryFull\NeoGlobal\GlobalException $e) {
            \NeoLibraryFull\NeoGlobal\global_warn_with_module_name("_global--options", "Error decoding option '$name'. Setting default value instead. " . $e->getMessage());
            get_or_set_option($name, $default);
            $cache[$name] = $default; return $default;
        }
    } else {
        $encoded_value = \NeoLibraryFull\NeoGlobal\json_encode_better($value); \NeoLibraryFull\NeoGlobal\global_log_with_module_name("_global--options", "Setting option '$name' to value " . (mb_strlen($encoded_value) > 100 ? mb_substr($encoded_value, 0, 100) . "…" : $encoded_value));
        $cache[$name] = $value;
        if (is_string(\NeoLibraryFull\NeoGlobal\val("neo_global__option_defaults")[$name] ?? null)) {
            if (!is_string($value)) { \NeoLibraryFull\NeoGlobal\throw_global_exception("Option '$name' must be a string because the default value is a string"); }
            update_option($name, $value, $autoload);
        } else { update_option($name, \NeoLibraryFull\NeoGlobal\json_encode_better($value), $autoload); }
    }
}


function get_or_set_option_by_function_name($function_name, $value, $delete) {
    $option_name = explode("option__", $function_name)[1];
    return get_or_set_option($option_name, $value, $delete);
}

_register_option("neo_wp_com",                                                     "neo-wp.com",         true);       function option__neo_wp_com                                                    ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_global__after_activation_redirect_neo_library_full", false,                true);       function option__neo_global__after_activation_redirect_neo_library_full($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_settings__hide_top_level_menu_enabled",                      false,                true);       function option__neo_settings__hide_top_level_menu_enabled                     ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_console_greeting__hide",                                     false,                true);       function option__neo_console_greeting__hide                                    ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_draw__svg_upload_enabled",                                   false,                true);       function option__neo_draw__svg_upload_enabled                                  ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_rename_alt_text__generation_enabled",                        true,                 true);       function option__neo_rename_alt_text__generation_enabled                       ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_rename_redirect__enabled",                                   true,                 true);       function option__neo_rename_redirect__enabled                                  ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_rename_redirect__list",                                      [],                   false);      function option__neo_rename_redirect__list                                     ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_rename_redirect__last_cleanup_timestamp",                    0,                    true);       function option__neo_rename_redirect__last_cleanup_timestamp                   ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_rename_undo__list",                                          [],                   false);      function option__neo_rename_undo__list                                         ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_image_cachebust__last_change_date",                          0,                    true);       function option__neo_image_cachebust__last_change_date                         ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_optimize__quality",                                          75,                   true);       function option__neo_optimize__quality                                         ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_optimize__retina_factor",                                    150,                  true);       function option__neo_optimize__retina_factor                                   ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_pro_color_theme__enabled",                                   true,                 true);       function option__neo_pro_color_theme__enabled                                  ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_pro__license_server_message",                                "",                   true);       function option__neo_pro__license_server_message                               ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_manager_installer__suppressed_plugins_list",                 [],                   true);       function option__neo_manager_installer__suppressed_plugins_list                ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tutorial__hidden_selectors",                                 [],                   true);       function option__neo_tutorial__hidden_selectors                                ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_bundler__domain_settings",                                   "",                   true);       function option__neo_bundler__domain_settings                                  ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_demo_content__imported",                                     false,                true);       function option__neo_demo_content__imported                                    ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_playground__source_server",                                  "",                   true);       function option__neo_playground__source_server                                 ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_debug__shorten_additional_message_enabled",                  true,                 true);       function option__neo_debug__shorten_additional_message_enabled                 ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_debug__show_debug_warnings_enabled",                         true,                 true);       function option__neo_debug__show_debug_warnings_enabled                        ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_debug__show_debug_tools_enabled",                            true,                 true);       function option__neo_debug__show_debug_tools_enabled                           ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_debug__error_message_extended_enabled",                      true,                 true);       function option__neo_debug__error_message_extended_enabled                     ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_debug__force_offer_update_enabled",                          false,                true);       function option__neo_debug__force_offer_update_enabled                         ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_debug__freemius_enabled",                                    false,                true);       function option__neo_debug__freemius_enabled                                   ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_debug__suppress_pro_enabled",                                false,                true);       function option__neo_debug__suppress_pro_enabled                               ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_debug__db_check_serialize_array_last_check",                 0,                    true);       function option__neo_debug__db_check_serialize_array_last_check                ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tool_code__code",                                            "",                   true);       function option__neo_tool_code__code                                           ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tool_code__code_timestamp",                                  0,                    true);       function option__neo_tool_code__code_timestamp                                 ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tool_database_replace__regex",                               '\\{_(.*?):(.*?)\\}', false);      function option__neo_tool_database_replace__regex                              ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tool_database_replace__replacement",                         '{_$2:$1}',           false);      function option__neo_tool_database_replace__replacement                        ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tool_database_replace__modifiers",                           "si",                 false);      function option__neo_tool_database_replace__modifiers                          ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tool_database_replace__preview_length",                      50,                   false);      function option__neo_tool_database_replace__preview_length                     ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tool_sync__pw",                                              "",                   false);      function option__neo_tool_sync__pw                                             ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tool_sync__target_hostnames",                                [],                   false);      function option__neo_tool_sync__target_hostnames                               ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tool_sync__post_slugs",                                      [],                   false);      function option__neo_tool_sync__post_slugs                                     ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }
_register_option("neo_tool_sync__option_names",                                    [],                   false);      function option__neo_tool_sync__option_names                                   ($value = null, $delete = false) { return get_or_set_option_by_function_name(__FUNCTION__, $value, $delete); }











function delete_all_neo_options() {
    global $wpdb;
    $option_names = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s", "neo_%")); /* phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching */ /* Direct database call to clean up not only autoloaded WP options and prevent leaving behind any lingering database junk. */
    foreach ($option_names as $option_name) {
        if (in_array($option_name, ["neo_tool_sync__target_hostnames", "neo_tool_sync__post_slugs", "neo_tool_sync__option_names", "neo_tool_sync__pw", "neo_tool_code__code", "neo_bundler__domain_settings"])) { continue; }
        delete_option($option_name);
    }
}


\NeoLibraryFull\NeoGlobal\add_action_hook("neo_init", function () {
    \NeoLibraryFull\NeoGlobal\register_rest_endpoint("/wp-json/neo/option-get-neo-library-full", "GET", fn () => \NeoLibraryFull\NeoGlobal\current_user_can__global_options(), function ($get_param) {
        return get_or_set_option($get_param("name"));
    });
});


\NeoLibraryFull\NeoGlobal\add_action_hook("neo_init", function () {
    \NeoLibraryFull\NeoGlobal\register_rest_endpoint("/wp-json/neo/option-set-neo-library-full", "POST", fn () => \NeoLibraryFull\NeoGlobal\current_user_can__global_options(), function ($get_param) {
        if (!str_starts_with($get_param("name"), "neo_")) { \NeoLibraryFull\NeoGlobal\throw_global_exception("Option name must start with 'neo_'"); }
        get_or_set_option($get_param("name"), $get_param("value"));
        return "OKAY";
    });
});
