Code Revisions
This plugin will help you to keep track of changes made to theme and plugin files through the WordPress code editors. You no longer need to worry about possibly breaking something with bad changes because you can always return to an older version of the file. Additionally the plugin helps you to red
About this tool.
This plugin will help you to keep track of changes made to theme and plugin files through the WordPress code editors. You no longer need to worry about possibly breaking something with bad changes because you can always return to an older version of the file. Additionally the plugin helps you to redo your changes when they might have been overwritten by a plugin update by easily showing you what changed. The revisions are handled in a way native to WordPress. Comfortably view revisions using the new revision viewer introduced in WordPress 3.6.
This plugin is part of my Google Summer of Code 2013 project at WordPress. You can find more information on make/core . It was also featured on wptavern.com if you are interested in some background information.
Developer’s Guide
code-revisions.php: The main plugin file. It defines constants, loads the other files, instantiates the classes if appropriate and contains the uninstall automatism.
inc/class-code-revisions.php: Loaded on all pages this class does multiple general things. It adds the custom post type required for saving the code revisions ( post_type() ) and redirects the user from the post editor ( wp-admin/edit.php ) to the appropriate code editor ( wp-admin/theme-editor.php or wp-admin/plugin-editor.php ) when he tries to view those posts directly ( redirect() ). Further more this class hooks into the WordPress revision restore process to not only restore the post but also the related file ( restore() ) and handles styling the WordPress revision viewer ( wp-admin/revisions.php ) when viewing code revisions so it feels more code-editor-ish ( styles() ).
inc/code-revisions-editors.php: This file contains the Code_Revisions_Editors class which, in contrast to the Code_Revisions class in class-code-revisions.php , is only loaded on the WordPress code editor pages using the load-plugin-editor.php and load-theme-editor.php hooks. Using either, if available, POST and GET data or falling back to the appropriate default file the class generates an array containing meta information on the currently viewed file ( generate_meta() ). In an attempt to have as less theme or plugin file specific code this array contains 4 strings:
- type: ‘plugin’/’theme’
- package: theme slug or ‘plugin/plugin.php’
- file: relative file path from the theme’s folder or the WordPress plugin directory
- checksum: md5-checksum of the file
Using this data the plugin can check the database for a related post and retrieve it’s id if available ( retrieve() ). The meta information array is stored as custom post meta data alongside a file’s post.