Kirby doesn't delete fields from content files if you later remove them from your blueprints, rename them, or if you add fields manually with an editor. Especially during development, you therefore often end up with a lot of unused stuff you will probably want to clean up before handing a project over to your client.
This script cleans up your page or file content files. It compares fields in the content files with those defined in the blueprint and removes all undefined fields, no matter if they contain content or not.
You can use the script with a pages or a files collection. By default, the script below runs through the complete pages index. Adapt $collection as required. It is not recommended to run through the complete index of a large site or through thousands of files because you might run into a timeout.
You can also set the fields to ignore in the $ignore array. By default the title and slug (for pages) as well as template and sort (for files) fields are ignored.
Create a new cleanup.php file in your site root and copy the script code into it.