What best practices should be followed when modifying and customizing PHP scripts like calendars or photo albums?

When modifying and customizing PHP scripts like calendars or photo albums, it is important to follow best practices to ensure the code remains maintainable and secure. This includes using proper naming conventions, organizing code into functions and classes, sanitizing user input to prevent SQL injection and cross-site scripting attacks, and documenting your changes for future reference.

// Example of sanitizing user input in a PHP script
$user_input = $_POST['user_input'];
$sanitized_input = filter_var($user_input, FILTER_SANITIZE_STRING);