Title: Code Revisions
Author: Alex
Published: <strong>2013年8月27日</strong>
Last modified: 2013年9月30日

---

プラグインを検索

![](https://ps.w.org/code-revisions/assets/banner-772x250.jpg?rev=772379)

このプラグインは **WordPress の最新3回のメジャーリリースに対してテストされていま
せん**。もうメンテナンスやサポートがされていないかもしれず、最新バージョンの WordPress
で使用した場合は互換性の問題が発生する可能性があります。

![](https://s.w.org/plugins/geopattern-icon/code-revisions_f1f1f1.svg)

# Code Revisions

 作者: [Alex](https://profiles.wordpress.org/ahoereth/)

[ダウンロード](https://downloads.wordpress.org/plugin/code-revisions.1.0.zip)

 * [詳細](https://ja.wordpress.org/plugins/code-revisions/#description)
 * [レビュー](https://ja.wordpress.org/plugins/code-revisions/#reviews)
 * [開発](https://ja.wordpress.org/plugins/code-revisions/#developers)

 [サポート](https://wordpress.org/support/plugin/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 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](https://make.wordpress.org/core/tag/code-revisions/).
It was also featured on [wptavern.com](http://www.wptavern.com/should-code-revisions-be-added-to-the-wordpress-core)
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.

When a file is opened in the editor and a related post is found in the database 
the plugin checks if the post’s content and the file’s content still match. If they
don’t the post is updated with the new content (which results in a new revision)
and the user is notified about the change using an admin notice (`handle_direct_changes()`).

On file updates through the code editor the plugin checks if the file has actually
changed before WordPress writes to it. Only when changes are found a revision needs
to be created. If no post is associated with the file yet a new post is created 
with the old contents. This post is then updated with the new content. This process
guarantees that there is a revision with the initial file content to which the user
can revert to (`handle_file_update()`). Additionally the plugin tries to do a syntax
check for `*.php` files to prevent breaking the WordPress installation (`check_syntax()`).
As mostly recommended the plugin utilizes `php -l` for this by writing the new contents
to a temporary file. If this feature is not available a more basic check using eval
is performed. When a syntax error is found the actual file is not written, but the
user is redirected back to the editor with a notification about the error and it’s
location with line highlighting.

**inc/plugged.php:** Contains a slightly changed version of the pluggable `wp_text_diff()`
function. `wp_text_diff()` is utilized for generating the diffs rendered in the 
revision viewer. Normally it strips leading, trailing and multiple successive whitespaces.
However this behavior is not very helpful when viewing code revisions, wherefore
the plugin suppresses it for revisions associated with the custom code revisions
post type.

**inc/metabox.php:** The template for the revision metabox.

**js/editors.js:** JavaScript for customizing the code editor pages (`wp-admin/plugin-
editor.php` and `wp-admin/theme-editor.php`). It adds the revisions metabox below
the editors, the revisions text with link next to the ‘Update File’ button and handles
the text replacement and line highlighting when a syntax error was found.

**css/editors.css:** Styles for the code editors. Enqueued in `inc/class-code-revisions-
editors.php -> scripts()`.

**css/viewer.css:** Styles for the revision viewer (`wp-admin/revisions.php`). Enqueued
only when viewing code revisions in `inc/class-code-revisions.php -> styles()`.

## 評価

このプラグインにはレビューがありません。

## 貢献者と開発者

Code Revisions はオープンソースソフトウェアです。以下の人々がこのプラグインに貢献
しています。

貢献者

 *   [ Alex ](https://profiles.wordpress.org/ahoereth/)

[“Code Revisions” をあなたの言語に翻訳しましょう。](https://translate.wordpress.org/projects/wp-plugins/code-revisions)

### 開発に興味がありますか ?

[コードを閲覧](https://plugins.trac.wordpress.org/browser/code-revisions/)するか、
[SVN リポジトリ](https://plugins.svn.wordpress.org/code-revisions/)をチェックする
か、[開発ログ](https://plugins.trac.wordpress.org/log/code-revisions/)を [RSS](https://plugins.trac.wordpress.org/log/code-revisions/?limit=100&mode=stop_on_copy&format=rss)
で購読してみてください。

## 変更履歴

#### 0.1

 * Post and revision creation on file edits

#### 0.2

 * Revision list metabox and revision viewing

#### 0.3

 * Revision restoring

#### 0.4

 * Take direct file changes (e.g. ftp or plugin/theme updates) into account

#### 0.5

 * Basic php syntax checking

#### 0.6

 * Enhanced error proofing & revision browsing

#### 0.7

 * More code appropriate revision viewer styling

#### 0.8

 * WordPress.org release with uninstall automatism and bug fixes

#### 0.9

 * Bug fixes, smaller enhancements and readme update

#### 0.95

 * Remove revisions on package (theme/plugin) uninstall

#### 1.0

 * Bug fix for older PHP versions.

## メタ

 *  バージョン **1.0**
 *  最終更新日 **13年前**
 *  有効インストール数 **10+**
 *  WordPress バージョン ** 3.6またはそれ以降 **
 *  検証済み最新バージョン: **3.7.41**
 *  言語
 * [English (US)](https://wordpress.org/plugins/code-revisions/)
 * タグ
 * [code](https://ja.wordpress.org/plugins/tags/code/)[Editors](https://ja.wordpress.org/plugins/tags/editors/)
   [revisions](https://ja.wordpress.org/plugins/tags/revisions/)[theme](https://ja.wordpress.org/plugins/tags/theme/)
 *  [詳細を表示](https://ja.wordpress.org/plugins/code-revisions/advanced/)

## 評価

 5つ星中4.2つ星

 *  [  4 5-星レビュー     ](https://wordpress.org/support/plugin/code-revisions/reviews/?filter=5)
 *  [  1 4-星レビュー     ](https://wordpress.org/support/plugin/code-revisions/reviews/?filter=4)
 *  [  0 3-星レビュー     ](https://wordpress.org/support/plugin/code-revisions/reviews/?filter=3)
 *  [  0 2-星レビュー     ](https://wordpress.org/support/plugin/code-revisions/reviews/?filter=2)
 *  [  1 1-星レビュー     ](https://wordpress.org/support/plugin/code-revisions/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/code-revisions/reviews/#new-post)

[すべてのレビューを見る](https://wordpress.org/support/plugin/code-revisions/reviews/)

## 貢献者

 *   [ Alex ](https://profiles.wordpress.org/ahoereth/)

## サポート

意見や質問がありますか ?

 [サポートフォーラムを表示](https://wordpress.org/support/plugin/code-revisions/)