前言介紹
- 這款 WordPress 外掛「Code Revisions」是 2013-08-26 上架。
- 目前有 20 個安裝啟用數。
- 上一次更新是 2013-09-30,距離現在已有 4233 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 3.6 以上版本才可以安裝。
- 有 6 人給過評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
ahoereth |
外掛標籤
code | theme | Editors | revisions | revision.php |
內容簡介
此外掛將幫助您跟踪通過 WordPress 代碼編輯器進行的佈景主題和外掛文件變更。您不再需要擔心不良更改可能會破壞某些內容,因為您可以隨時恢復文件的較舊版本。此外,此外掛將幫助您重新執行更改,當這些更改可能已被插件更新覆蓋,將輕鬆顯示更改內容。修訂版以 WordPress 原生方式處理。使用 WordPress 3.6 引入的新修訂檢視器舒適地查看修訂版。
此外掛是我在 WordPress 的 2013 年 Google Summer of Code 專案的一部分。您可以在 make/core 上找到更多訊息。如果您有興趣了解更多背景資訊,它也出現在 wptavern.com 上。
開發人員指南
- code-revisions.php:主要的外掛檔案。它定義常量、載入其他檔案、在適當的情況下實體化類別並包含卸載自動化方法。
- inc/class-code-revisions.php:在所有頁面加載此類別,它執行多個一般性操作。它添加所需的自訂文章類型以保存程式碼修訂版(post_type()),並在用戶嘗試直接查看這些文章(redirect())時將用戶從文章編輯器(wp-admin/edit.php)重定向到適當的代碼編輯器(wp-admin/theme-editor.php 或 wp-admin/plugin-editor.php)。此外,此類別連接到 WordPress 修訂版還原程序,不僅還原文章,還還原相關的檔案(restore()),並處理 WordPress 修訂版檢視器(wp-admin/revisions.php)的樣式,以使其感覺更像程式碼編輯器(styles())。
- inc/code-revisions-editors.php:此檔案包含 Code_Revisions_Editors 類別,它與 class-code-revisions.php 中的 Code_Revisions 類別相比,只會在使用 load-plugin-editor.php 和 load-theme-editor.php 鉤子載入 WordPress 代碼編輯器頁面上載入。使用 POST 和 GET 資料或回退到適當的預設檔案之一,該類別會生成包含當前查看的檔案的元資訊陣列(generate_meta())。爲了具有較少的佈景主題或外掛專有程式碼,此陣列包含 4 個字串:
- 類型:'plugin'/'theme'
- 套件:佈景主題 Slug 或 'plugin/plugin.php'
- 檔案:從佈景主題的資料夾或 WordPress 外掛目錄的相對檔案路徑
- 校驗和:檔案的 md5 校驗和
- 利用此資料,外掛可以檢查數據庫是否有相關的文章並檢索其 ID(如果可用)(retrieve())。元資訊陣列存儲為自訂文章的附加資料,並沿著文章一起儲存檔案。
- 當在編輯器中打開檔案並在數據庫中找到相關的文章時,外掛會檢查文章的內容和檔案的內容是否仍相符。如果它們不相符,則更新文章與新內容(導致新的修訂版),並使用管理員通知通知使用者存在變更(handle_direct_changes())。
- 在透過代碼編輯器進行檔案更新時,外掛會在 WordPress 寫入檔案之前檢查檔案是否實際有更動。僅在發現更改時才需要建立修訂版。如果檔案尚未與文章相關聯,它將創建具有舊內容的新文章。然後更新此文章的新內容。此過程保證有一個具有初始檔案內容的修訂版。
原文外掛簡介
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.
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().
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Code Revisions」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
0.8 | 0.9 | 1.0 | 0.95 | trunk |
延伸相關外掛(你可能也想知道)
WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager 》插入標頭和頁腳 + 完整的 WordPress 代碼片段外掛, WPCode (前稱为 WPBeginner 的 "插入標頭和頁腳")是使用率超过 100 万个网站的 WordPress 代码片段外掛中...。
Code Snippets 》Code Snippets 是在您的網站上運行程式碼片段的簡單,清潔和簡單的方法。它消除了將自定義片段添加到您的佈景主題的 functions.php 檔案的需求。, 現在提供 C...。
Simple Custom CSS Plugin 》無需麻煩地將自訂 CSS 新增到 WordPress 網站中。, 這是一個易於使用的 WordPress 外掛,可以添加自訂 CSS 樣式以覆寫外掛和佈景主題的預設樣式。該外掛旨在...。
Shortcoder — Create Shortcodes for Anything 》Shortcoder 外掛可讓您建立 HTML、JavaScript、CSS 和其他代碼片段的自訂捷徑。現在,這些捷徑可以在文章/頁面中使用,並且該片段將取代其位置。, ✍ 輕鬆建立...。
Head & Footer Code 》Head & Footer Code 插件可以讓你在不是開發人員的情況下,添加自定義代碼片段(JavaScript、CSS 或 HTML)到網頁中。您可以將代碼放置在 (...。
Scripts n Styles 》這個外掛讓管理員用戶能夠將自訂的 CSS 和 JavaScript 直接添加到個別文章、頁面或任何註冊的自訂文章類型中,也可以將類別添加到 body 標籤和文章容器中。還...。
SyntaxHighlighter Evolved 》現在支援 WordPress 5.0 中的新區塊編輯器!, SyntaxHighlighter Evolved 讓您可以輕鬆地在網站上張貼帶有語法加亮功能的程式碼,而不會失去格式或做任何手動...。
Code Embed 》注意: WordPress 5.0 及以上版本的使用者請查看常見問題以了解如何在區塊編輯器中使用此外掛。, Code Embed 外掛允許您在文章中嵌入程式碼(JavaScript 和 H...。
PHP Everywhere 》注意:此外掛更新至 3.0.0 版本是一項重大變更,將移除 [php_everywhere] 短代碼和小工具。請透過外掛設定頁面中的升級嚮導,將原本的代碼轉換為 Gutenberg ...。
Highlighting Code Block 》「Highlighting Code Block」外掛可讓你以一個點擊的方式添加一個有語法突顯的程式碼區塊。, 它支援「區塊編輯器」和「傳統編輯器」。, (不過,我們建議在「...。
CSS & JavaScript Toolbox 》感謝您查看我們的程式碼片段外掛。我相信它將完全符合您的需求。, 適用於以下情況:, , 前端修改(無需修改主題文件), 添加功能(無需修改functions.php), ...。
Advance Custom HTML 》這是一款用來專業編寫 HTML 代碼的高級 HTML 編輯器,提供不同的樣式、縮排與更多功能。, Advance Custom HTML 是一款功能強大、彈性十足的區塊外掛,讓您可...。
Code Block Pro – Beautiful Syntax Highlighting 》展示你美麗的程式碼,不僅僅是顯示它!這個版塊外掛提供編輯程式碼塊的功能,直接運行你的程式碼,使用與受歡迎的 VS Code 編輯器相同的渲染引擎。此外掛提供...。
Code Syntax Block 》代碼語法區塊(Code Syntax Block)擴充了 WordPress 區塊編輯器,使用 Prism 語法高亮工具為核心代碼區塊添加了語法高亮支持。, Prism 語法高亮工具在前端執...。
Foxtool All-in-One: Contact chat button, Custom login, Media optimize images 》總結:Foxtool 是根據管理 WordPress 網站的真實需求而開發的產品。經過一段時間的發展,Foxtool 已成為網站管理員不可或缺的外掛程式。該外掛擁有許多值得注...。