[wordpress插件] Code Revisions代码修订

wordpress 插件 文章 5 天前 0 6 全屏看文
评分
84
描述

This plugin will help you to keep track of changes made to theme and plugin files through the WordPress code editors.

此插件将帮助您通过WordPress代码编辑器跟踪对主题和插件文件所做的更改。

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.

这些修订以WordPress原生的方式进行处理。

Comfortably view revisions using the new revision viewer introduced in WordPress 3.6.

使用WordPress 3.6中引入的新修订版查看器轻松查看修订。

This plugin is part of my Google Summer of Code 2013 project at WordPress.

此插件是我在WordPress上的Google Summer of Code 2013项目的一部分。

You can find more information on make/core.

您可以在 make / core 上找到更多信息。

It was also featured on wptavern.com

wptavern.com

> if you are interested in some background information.

>如果您对某些背景信息感兴趣。

Developer’s Guide

开发人员指南

code-revisions.php: The main plugin file.

code-revisions.php:主插件文件。

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.

inc / class-code-revisions.php:该类在所有页面上加载时会执行多项常规操作。

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

它添加了保存代码修订所需的自定义帖子类型( post_type()),并将用户从帖子编辑器( wp-admin / edit.php )重定向到

appropriate code editor (wp-admin/theme-editor.php or wp-admin/plugin-editor.php) when he tries to view those posts directly (

当他尝试直接查看这些帖子时,适当的代码编辑器( wp-admin / theme-editor.php wp-admin / plugin-editor.php

redirect()).

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-adminevisions

此外,该类还与WordPress版本还原过程挂钩,不仅可以还原帖子,还可以还原相关文件( restore()),并处理WordPress版本查看器的样式( wp-admin / revisions

.php) when viewing code revisions so it feels more code-editor-ish (styles()).

.php ),以便在查看代码修订时感觉更像是代码编辑器风格( styles())。

inc/code-revisions-editors.php: This file contains the Code_Revisions_Editors class which, in contrast to the Code_Revisions class in <

inc / code-revisions-editors.php:该文件包含 Code_Revisions_Editors 类,与<

code>class-code-revisions.php, is only loaded on the WordPress code editor pages using the load-plugin-editor.php and load-theme-editor.php

code> class-code-revisions.php ,仅使用 load-plugin-editor.php load-theme-editor.php加载到WordPress代码编辑器页面上

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

使用 POST GET 数据(如果可用),或者使用适当的默认文件,该类将生成一个包含有关当前查看文件的元信息的数组( generate_meta

()).

())。

In an attempt to have as less theme or plugin file specific code this array contains 4 strings:

为了减少主题或插件文件的特定代码,此数组包含4个字符串:

    • type: ‘plugin’/’theme’
    • 类型:“插件” /“主题”

    • package: theme slug or ‘plugin/plugin.php’
    • 软件包:主题插件或“ plugin / plugin.php”

    • file: relative file path from the theme’s folder or the WordPress plugin directory
    • 文件:主题文件夹或WordPress插件目录中的相对文件路径

    • checksum: md5-checksum of the file
    • 校验和:文件的md5-校验和

    Using this data the plugin can check the database for a related post and retrieve it’s id if available (retrieve()).

    使用此数据,插件可以检查数据库中的相关帖子并检索ID(如果有)( 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()).

    如果没有,则该帖子将使用新内容进行更新(这将导致新的修订),并通过管理员通知( handle_direct_changes())通知用户有关更改的信息。

    On file updates through the code editor the plugin checks if the file has actually changed before WordPress writes to it.

    在通过代码编辑器更新文件时,插件会在WordPress写入文件之前检查文件是否已实际更改。

    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()).

    此过程保证存在一个带有初始文件内容的修订版本,用户可以将其还原为( handle_file_update())。

    Additionally the plugin tries to do a syntax check for *.php files to prevent breaking the WordPress installation (check_syntax()).

    另外,该插件会尝试对 *。php 文件进行语法检查,以防止破坏WordPress安装( check_syntax())。

    As mostly recommended the plugin utilizes php -l for this by writing the new contents to a temporary file.

    正如大多数推荐的那样,该插件通过将新内容写入临时文件来利用 php -l <​​/ code>。

    If this feature is not available a more basic check using eval is performed.

    如果此功能不可用,则使用eval进行更基本的检查。

    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.

    inc / plugged.php:包含可插拔 wp_text_diff()函数的稍微变化的版本。

    wp_text_diff() is utilized for generating the diffs rendered in the revision viewer.

    wp_text_diff()用于生成在修订版查看器中呈现的差异。

    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.

    inc / metabox.php:修订版元框的模板。

    js/editors.js: JavaScript for customizing the code editor pages (wp-admin/plugin-editor.php and wp-admin/theme-

    js / editors.js:用于自定义代码编辑器页面的JavaScript( wp-admin / plugin-editor.php wp-admin / theme-

    editor.php).

    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.

    css / editors.css :代码编辑器的样式。

    Enqueued in inc/class-code-revisions-editors.php -> scripts().

    排入 inc / class-code-revisions-editors.php-> scripts()

    css/viewer.css: Styles for the revision viewer (wp-adminevisions.php).

    css / viewer.css :修订版查看器的样式( wp-admin / revisions.php )。

    Enqueued only when viewing code revisions in inc/class-code-revisions.php -> styles().

    仅当在 inc / class-code-revisions.php-> styles()中查看代码修订时才入队。

下载地址
https://downloads.wordpress.org/plugin/code-revisions.1.0.zip
-EOF-