#!/bin/bash

echo "INSTALLING NEW WEB SITE"
echo "User Name: $user_name"
echo "Domain: $domain"

# Find and replace WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT in config
wp_config_path=$(su - $user_name -c "wp config path --type=php")
search_limit="define( 'WP_MEMORY_LIMIT', '128M' );"
replace_limit="define( 'WP_MEMORY_LIMIT', '384M' );"
search_max_limit="define( 'WP_MAX_MEMORY_LIMIT', '128M' );"
replace_max_limit="define( 'WP_MAX_MEMORY_LIMIT', '384M' );"

# Perform the replacements in wp-config.php
if grep -q "$search_limit" "$wp_config_path"; then
    sed -i "s/$search_limit/$replace_limit/" "$wp_config_path"
fi
if grep -q "$search_max_limit" "$wp_config_path"; then
    sed -i "s/$search_max_limit/$replace_max_limit/" "$wp_config_path"
fi

echo "Memory limits in wp-config.php updated."

sudo /etc/php/changephp.sh
echo "***post-processing script complete***"
echo ""
