How can the script be optimized to only run once during the initial setup of the website?

The script can be optimized to only run once during the initial setup of the website by using a flag or a configuration setting to check if the script has already been executed. This way, the script will only run if it hasn't been executed before.

// Check if the setup script has already been executed
if (!get_option('website_setup_completed')) {
    // Run the setup script
    // Your setup code here

    // Set a flag to indicate that setup has been completed
    update_option('website_setup_completed', true);
}